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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
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
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.
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