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.
By david_ross at 2003-12-05 14:37
TITLE: Using rsync to mirror data between servers
Introduction
This LinuxAnswer describes how to mirror 2 systems using rsync over ssh.
I will only talk about a live server and a backup server where the backup server will connect to the live server to pull the data that is to be backed up.
Assumptions
1) You know how to open up a terminal and type a few basic commands.
2) You have a working ssh server and client installed. If not then see: ftp://ftp.ca.openbsd.org/pub/OpenBSD...rtable/INSTALL
3) You have private/public keys generated to allow passwordless logins to the live server form the backup server. If not then see LinuxAnswer Public key authentication with ssh. In relation that howto the backup server is the client and the live server is the server.
Why would you want to?
There are many reasons so I'll just list a few:
1) Data transfer is fast as rsync only copies modified files
2) Running it over ssh encrypts the data transfer so it is more secure than other methods
The real howto
1) Decide on the directories you need to backup on the live server assuming it is a webserver this may be "/home/httpd"
2) Decide on the options you want. The most common I would use are: -a Archive mode this is a combination of "-rlptgoD" basically it works recursively and maintains file information such as creation dates, permissions etc. See the man page for detailed info. -v Increase the verbosity. This will let you see what is transferred -z Compress data so that it is a quicker transfer --delete-after Delete any files that have been deleted on the live server -e ssh Most importantly, run the transfer over an ssh connection
A full list can be obtains from "man rsync".
3) Try a dry run on the backup server with "-n" to make sure any typos don't totally screw your system. This will just show what would be done: rsync -e ssh -avzn --delete-after user@liveserver:/home/httpd /home
4) If everything went as expected you can give it a go without -n rsync -e ssh -avz --delete-after user@liveserver:/home/httpd /home
You should get the info about the files being transferred. Running it again should be quicker as very little has probably changed.
5) That should be it, just try creating and deleting a few files and run rsync to make sure the changes occur
Automating the process
The obvious answer running the rsync commands on the backup server via cron.
A basic example being to mirror every hour on the hour: 0 * * * * rsync -e ssh -avz user@liveserver:/home/httpd /home 2>&1 > /var/log/hourly_backup.log
Then remove deleted files every night: 30 0 * * * rsync -e ssh --delete-after -avz user@liveserver:/home/httpd /home 2>&1 > /var/log/nightly_backup.log
I just wanted to say thank you for this great HOWTO.
I got to rsync from zero knowhow and now my productive server is backuped to my other server like a star.
Good job!
by Rugemalira on Wed, 2004-04-21 23:55
Dear frinds,
I use rsync to back up a live server to another server. I use this command
rsync -e ssh -avz --delete-after user@liveserver:/home/httpd /home
then I am prompted to enter a password. Now when I enter the same command in the crontab nothing happens. I think the problem is may requre a password to connect.
Now How do I enter the password in to the crontab so that this process is automated? The command in the crontab I us is; 0 * * * * rsync -e ssh -avz user@liveserver:/home/httpd /home 2>&1 > /var/log/hourly_backup.log
Crispin.
by browny_amiga on Thu, 2004-04-22 08:49
Oh yes, that is an issue. Usually you need to enter a password and cron of course, cannot do that.
Some crazy idea would be to put the password into a file and read it from there, but this is a terrible way to work.
Instead, you can create a passwordless loging for the machine that makes the backup to the other. Look up the HOWTO about ssh, it is described there, worked for me like a charm.
In essence you generate a key on the backup machine and then include that key into the "trusted keys" file in the other machine, so it lets it login without a password.
by atomicx on Tue, 2004-07-20 12:02
This is a great topic/article. I was wondering if there was at good way using rsync to keep 2 computers synced up if files are being updated on either machine.
by Rugemalira on Wed, 2004-10-20 06:56
browny_amiga, it worked, thanks.
Atomicx, it is posible, just generate the private in the server(see the howto, man pages), then copy it to the backup sever, even if you have more than one backup severs, just copy the same key to all severs.
cris
by linuxlogo on Sun, 2006-10-29 17:17
you need to exchange the SSH public key b/w the servers so that you need not to provide any password. There is a link above which shows how to do that. Cheers.
by billymac00 on Wed, 2007-09-12 11:31
(newbie). I just used the rsync successfully to an external NDAS. My question is whether I am foolish to think this is a truly useful backup, and if it is, does one just rsync the files back? I speak to the case of having backed up a particular folder (non OS application files) off the server, and then later needing that older/intact version off the NDAS to recreate/fix same on server. Thanks.
by yashvanth on Thu, 2012-03-29 01:37
hi can anyone tell me the complete procedure how to setup the rsync server . i am very new to linux and somehow managed to write some script to take backup locally using rsync.
now i need to take the backup remotely.please help me to do this one
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
I got to rsync from zero knowhow and now my productive server is backuped to my other server like a star.
Good job!
I use rsync to back up a live server to another server. I use this command
rsync -e ssh -avz --delete-after user@liveserver:/home/httpd /home
then I am prompted to enter a password. Now when I enter the same command in the crontab nothing happens. I think the problem is may requre a password to connect.
Now How do I enter the password in to the crontab so that this process is automated? The command in the crontab I us is; 0 * * * * rsync -e ssh -avz user@liveserver:/home/httpd /home 2>&1 > /var/log/hourly_backup.log
Crispin.
Some crazy idea would be to put the password into a file and read it from there, but this is a terrible way to work.
Instead, you can create a passwordless loging for the machine that makes the backup to the other. Look up the HOWTO about ssh, it is described there, worked for me like a charm.
In essence you generate a key on the backup machine and then include that key into the "trusted keys" file in the other machine, so it lets it login without a password.
Atomicx, it is posible, just generate the private in the server(see the howto, man pages), then copy it to the backup sever, even if you have more than one backup severs, just copy the same key to all severs.
cris
now i need to take the backup remotely.please help me to do this one