IT Mirror a Website 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. For this section, I will be drawing from information that I got from this rsync tutorial at Plus, I will give you some more specific instructions pertaining to the typical file structure found on CPanel servers.

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:

  1. ssh into your mirror server.
  2. Enter the following command: rsync -e ssh -avzn –delete-after user@serverIP:~/public_html ~/
    • -e ssh – tells rsync to run the transfer over a secure connection
    • -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 transfered
    • –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)
  3. 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 -avz –delete-after user@serverIP:~/public_html ~/
  4. To test things further, you can try creating and deleting some files on your production server and running rsync again to make sure your mirror is syncing with your production server. In addition, after your first run of rsync, you should notice it runs faster because it only needs to transfer the files that have changed.
  5. Once you are assured that you have everything working correctly, use the CPanel on your mirror server to add your rsync commands as cron jobs.

Now that you have rsync backing up your files, you are ready to Mirror MySQL Databases

Sign up for our newsletter to stay up to
date with tech news!