| 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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
|
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
|
|
|
|
All times are GMT -5. The time now is 03:22 AM.
|
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