WenderHost

(865) 270-6715
or email us

Mirror a Dynamic Website on a CPanel/WHM Server

Step 3: 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. For this section, 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 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 your MySQL databases using mysqldump.

4 Responses to “Mirror a Dynamic Website on a CPanel/WHM Server”

  1. Naseer Khan says:

    Hi,
    Please could you tell me if you have ever done mirroring for the plesk web servers.
    Thanking you.
    Regards,
    Naseer.

  2. Davi Souza says:

    This is for ressellers, how to backup entire dedicated server with cpanel and whm???

    the sql sync isn“t good enough, imagine if i need to create all database of accounts??? is it possible to copy all information between the servers???

    thanks - but at all is very good tutorial....

  3. AndyW says:

    Michael, I find your article very informative and helpfull. Thank you very much for same.

    Was wondering since you posted it on 2007, how has the setup performed since then? Are you still using it or have you moved to a more advanced setup.

    Just want to get your production experience of it, before I implement it on a bunch of websites.

    Thanks in advance.

  4. Peter says:

    If the server still asks for password then you need to check the following permission in your server.

    * Change the permissions of .ssh to 700
    * Change the permissions of .ssh/authorized_keys2 to 640

    It took me 2 days to figure this out.

Leave a Reply

Copyright © 2007. All Rights Reserved.
WP Full Site Theme modified by Michael Wender. • Log in.