Using Rsync to mirror data between servers Rsync is a handy open-source utility for Unix systems which will backup files between servers only copying the files that have changed since the last time it was run. I will be drawing from information that I got from this
rsync tutorial at LinuxQuestions.org. Plus, I will give you some more specific instructions pertaining to the typical file structure found on CPanel servers.
For this to succeed. we must enable key based ssh authentication. Read how to
setup key based ssh authentication tutorial.
For this example, lets say you want to backup the files in the web root directory on your CPanel production server. Typically, CPanel servers call this directory
public_html. To backup this directory, do the following:
- SSH into your mirror / destination server and enter the following command:
rsync -e "ssh -p sshCustomPort" -avzn -delete-after user@serverIP:~/public_html ~/
- -e ssh - tells rsync to run the transfer over a secure connection
- -p - tells ssh to use custom SSH port other than default port 22
- -a - archive mode, this works recursively through your folder structure, maintaining creation dates, permissions, etc.
- -v - verbose, lets you see the output of the script
- -z - compress the data, speeds up the transfer
- -n - dry run, shows what would have been transferred
- -delete-after - delete any files on the mirror that have been deleted on the production server
- user - the username for your production server
- serverIP - the IP address for your production server
- ~/public_html - the production server directory that you want to backup
- ~/ - the root directory of your mirror server (generally this will always be the same if you want to maintain the same directory structure as your production server)
- Check the output. If everything went OK, you can run the same command and drop the n to do a real backup:
rsync -e "ssh -p sshCustomPort" -avz -delete-after user@serverIP:~/public_html ~/