Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
12-03-2009, 10:00 PM
|
#1
|
Member
Registered: Nov 2009
Posts: 49
Rep:
|
Pulling database backups
Hi,
I'm a Linux administrator in my company, and I'm working in with a server in a different location from the production server of my office. I've a task of pulling daily database backups (mysql) from the production server to my local server.
The original backups are of course in the production server. Backups are done daily in that server, using automysql backup script. So for example, for the database named myob, the backups are as follows :
If today were Thursday, and the backup time set in cron was 12.30 p.m. , then the backup would be named as below :
myob_2009-12-03_12h30m.Thursday.sql.gz
If it were Friday, then the backup name would be :
myob_2009-12-04_12h30m.Friday.sql.gz
and so it goes.
So how do I pull the database backups daily from Monday to Friday to my local server. Is there a way to use scp command in a script and then put that script in cron as a daily cron job to pull the database backups?
Pls help. Tqs.
Last edited by anaigini45; 12-03-2009 at 10:01 PM.
|
|
|
12-03-2009, 10:04 PM
|
#2
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
Hi, welcome to LQ!
The best tool for the job in this case is probably rsync
Have a read of its man-page. It's well written, and full
of good usage examples.
Cheers,
Tink
|
|
|
12-03-2009, 10:28 PM
|
#3
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,397
|
You can indeed use rsync. Alternately, you can use scp with authorised keys to avoid it prompting for a passwd.
|
|
|
12-04-2009, 07:03 AM
|
#4
|
Senior Member
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197
Rep:
|
I would think it would be easier to combine the transfer with the script that does the backup, on the remote machine. That simplifies things, because it generates the dump file, gzips it, and then scp's it to your server. As chrism01 says, use authorized keys (whichever way you go). Detailed howto here http://sial.org/howto/openssh/publickey-auth/.
A completely different way of dealing with it would be to run the MySQL backups from your machine using ZRM for MySQL -- http://www.zmanda.com/backup-mysql.html. There are "quick start" examples at the end of the Users Manual -- http://wiki.zmanda.com/index.php/Zma...L_Users_Manual.
|
|
|
12-06-2009, 10:36 PM
|
#5
|
Member
Registered: Nov 2009
Posts: 49
Original Poster
Rep:
|
So does this mean that I've to create a separate script which holds the line:
scp -r [filename]/ user@serveradd:/path
and call it in cron?
But the name of the backups are different everyday, because the backups are named according to the day, so how do I use the method mentioned?
Last edited by anaigini45; 12-06-2009 at 10:38 PM.
|
|
|
12-07-2009, 01:03 AM
|
#6
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
rsync would handle that - only copy stuff that's different between
the two machines. Alternatively you could make a shell-script
that creates a matching time-stamp for you name and build the
name on the fly before scp-ing.
|
|
|
12-07-2009, 10:42 PM
|
#7
|
Member
Registered: Nov 2009
Posts: 49
Original Poster
Rep:
|
Ok....works successfully. All the database backups till the current date is pulled into my local server from the production server using rsync.
Now my task is to upload these backups to my client's server.
That I have not done yet. But what I have to do is to create a excel sheet or sth to track/show the downloading/uploading process...
Pls guide me on this..
Tqs.
|
|
|
12-08-2009, 12:23 AM
|
#8
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,397
|
You need to tell us a bit more about what you want.
If its an after-the-fact he can check situation, just create an entry in a DB and use a website to pull up the records; assuming a non-tech end-user.
You could just email him the result, it's easy enough.
|
|
|
12-08-2009, 01:51 AM
|
#9
|
Member
Registered: Nov 2009
Posts: 49
Original Poster
Rep:
|
Is there a way to actually make an excel sheet track the downloading and uploading of each of the backups automatically?
Maybe I did not use the word automatically? Is it possible to make rsync or sth work automatically daily (to pull/download the backups from the production server and then push/upload into the client's server) ?
What I mean is I do not have to interfere. I just set things up and it is supposed to work the way I want it.
A good example would be using the automysqlbackup script. If the script is located in cron, then the backups are done automatically without my interference. At the specified time everyday, the backups are made.
Is it possible to do the same with pulling and pushing the backups? AND ALSO making excel track these at the same time?
I had to clear my doubt. Thanks.
|
|
|
12-08-2009, 07:48 AM
|
#10
|
Senior Member
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197
Rep:
|
rsync can push or pull. Do it by hand to see it work. Then put it in cron. It can be automated in the same way as automysqlbackup or anything else.
If you really want a spreadsheet, a spreadsheet will easily import a comma delimited or tab delimited file. Decide what fields you want and then append a record to the file each time your script runs. Have a spreadsheet with a macro that reads that file in. Then your client/boss/whoever can open the spreadsheet and it will automatically (with the macro) import and format the file. You'll have to play with that and figure it out. It will depend, of course, on your spreadsheet and platform of choice at that end.
|
|
|
12-10-2009, 05:05 AM
|
#12
|
Member
Registered: Nov 2009
Posts: 49
Original Poster
Rep:
|
Hi,
I created the script with the rsync command below :
rsync -avz 7-h2.my00001.cserver.mygrid.asia:/backups/daily/myob/ /backups/myob
I then saved the script as pull.sh and made it executable and located it in the /sbin directory.
After that I created a cronjob for that script in using crontab -e :
Quote:
45 18 * * * /sbin/pull.sh > /tmp/pulling.log
|
I don't get any results (the backups are not pulled into my server, and there is no output in the log file.
So I assume there must be some syntax problem with the script. Pls help me with this as I do not know what else to write in the script for it to work.
|
|
|
12-10-2009, 06:57 AM
|
#13
|
Senior Member
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197
Rep:
|
Take it one step at a time to figure out what's up. In post #7, you said it works. So, you had an rsync command that you executed by hand that worked. Presumably, that is what you put in your script. Is the script executable? Did you try just running it by hand? Are you sure there were changes on the remote server to copy when the script ran? The crontab entry looks alright, and, if you edited it using `crontab -e` it would have complained if there were format errors. Yours is set to execute at 6:45pm every day. If the cron job generates error output, it should also generate an email to the user the cron job is running as. If you aren't getting email, running it by hand would show you any errors.
|
|
|
12-10-2009, 04:50 PM
|
#14
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,397
|
Also see my note in post #11 about using the full path to cmds in a cron script. cron likely can't find the rsync cmd.
|
|
|
12-23-2009, 04:33 AM
|
#15
|
Member
Registered: Nov 2009
Posts: 49
Original Poster
Rep:
|
I've done some research, and am wondering, is this a correct reference material ?
Using Rsync and SSH
Do I really have to setup the ssh key and use a port number and use ssh with rsync for it to happen?
Previously, the script that I used in cron was :
Code:
#!/bin/sh
RSYNC=/usr/bin/rsync
LPATH=/backups/daily/myob/
RPATH=root@7-h2.my00001.cserver.mygrid.asia:/backups/daily/myob/
$RSYNC -avz $RPATH $LPATH >> /tmp/output.txt
It did not work. (The backup files were not pulled to my local server and there was no output in the output.txt)
|
|
|
All times are GMT -5. The time now is 12:49 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|