ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi, I have a little problem that I canīt seem to find the solution,
I have a simple script that what it does is:
Stop Services
Tar some folders
Log in to an FTP
PUT the Tar Folders on the FTP server (2003)
Remove the previously created tars
Start the Services Again.
But here is the problem, if the Tars, Log in and Put work fine the services do start up ok, but if I get any problem, the script dies, and the services donīt come back up.
So How can I modify this script so that if it fails the Backup procedure, still start the services up anyway, because they are very important "MYSQL
and CVSD")
Here is a Copy of the Script
Code:
#!/bin/bash
cd /root
/etc/init.d/cvsd stop
/etc/init.d/mysql stop
tar czvf source_`date +%y%m%d.tar.gz` /home/source/*
tar czvf mysql_`date +%y%m%d.tar.gz` /var/lib/mysql/*
ftp -inv 192.168.1.2 << EOF
user user1 backup
verbose off
prompt off
binary
put source_`date +%y%m%d.tar.gz`
put mysql_`date +%y%m%d.tar.gz`
bye
EOF
rm source_`date +%y%m%d.tar.gz`
rm mysql_`date +%y%m%d.tar.gz`
/etc/init.d/mysql start
/etc/init.d/cvsd start
I do not understand why the service start commands are not being executed. As it stands, if any of the commands fail, execution proceeds through the script executing further commands (arguably not ideal) until the service start commands are executed. Or does the script hang in one of the commands so it doesn't get to the end? Or do you kill the script before it gets to the end.
The solution to the problem is dependent on what is going wrong.
I do not understand why the service start commands are not being executed. As it stands, if any of the commands fail, execution proceeds through the script executing further commands (arguably not ideal) until the service start commands are executed. Or does the script hang in one of the commands so it doesn't get to the end? Or do you kill the script before it gets to the end.
The solution to the problem is dependent on what is going wrong.
Looks like the service wont start if any problem comes up, lets say, it cannot copy a file because of permissions, or because its been used, or it cannot connect to the FTP server.
Let me also point that this works fine , (when it works fine), it had been doing some backups, but when the error comes, boom no services come back.
Is there anyway to get this script get generate an error log so that I know what the problem is, what do you think it could be?
Difficult to advise without seeing the errors. Of course logging (and error trapping) can be added to the script. For starters you could run it using tee to get output on screen and in log
Difficult to advise without seeing the errors. Of course logging (and error trapping) can be added to the script. For starters you could run it using tee to get output on screen and in log
Code:
./mybackup.sh 2>&1 | tee mybackup.log
Great, I will run that command with the backup script and see what it comes out.
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197
Rep:
I would also reorder your script so that the starting of services is done after the tar. This is sort of the way people do things with snapshots, and part of the point of snapshots. They reduce the necessary down time window. So, in your case, stop services, tar the directories, start the services, then proceed with copying them to the other server and so on.
The way I do backups is to stop any services that need to be stopped (not all do), take a snapshot, start them up again, then proceed with backing up the snapshot. That gives a service down time of just seconds.
You can also have a separate cron script that starts up after the backup script and runs in a loop. It would check to see if the backup script is still running, and loop if it is. If the backup script is no longer running, then it would check services and launch them if necessary. Service monitoring utilities automate that whole process in a more general sense, but what have to be made aware of your backup procedure.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.