LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-24-2009, 03:06 AM   #1
Greenberet88x
LQ Newbie
 
Registered: Sep 2009
Posts: 3

Rep: Reputation: 0
Bash Backup Script Help..............!


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
Any help will be really appreciated,

Many thanks in advance!...
 
Old 09-24-2009, 03:45 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,531
Blog Entries: 27

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
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.
 
Old 09-24-2009, 04:20 AM   #3
Greenberet88x
LQ Newbie
 
Registered: Sep 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by catkin View Post
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?

Thanks for your response!
 
Old 09-24-2009, 04:43 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,531
Blog Entries: 27

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
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
 
Old 09-24-2009, 05:10 AM   #5
Greenberet88x
LQ Newbie
 
Registered: Sep 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by catkin View Post
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.

thanks a lot for your fast answers.
 
Old 09-24-2009, 07:17 AM   #6
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,189

Rep: Reputation: 105Reputation: 105
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.
 
  


Reply

Tags
backup, bash, ftp, script, service, sql


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash - backup script - need help with my if-then-else :D fruitwerks Programming 12 04-11-2009 01:34 PM
Bash script for database backup #cousin# Programming 8 08-29-2008 06:00 AM
bash backup script kristof_v Programming 4 07-24-2007 07:33 PM
Need help with a bash script that does a backup jamtech Programming 8 06-07-2007 11:36 PM
Backup script in bash gauge73 Programming 13 10-17-2005 06:25 AM


All times are GMT -5. The time now is 08:34 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration