How to Sync Two Apache Web Servers/Websites Using Rsync

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.95/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Tarunika Shrivastava

I am a linux server admin and love to play with Linux and all other distributions of it. I am working as System Engineer with a Web Hosting Company.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

35 Responses

  1. Dhaal says:

    I also need after rsync completes the job – the result should be emailed to website owner ?

  2. umesh says:

    Dear Ravi,

    I have a website on Old server CentOS release 5.11 which is running a local webportal on Apache Server version: Apache/2.2.3.

    I want to move this webportal to the new OS CentOS Linux release 7.2 on Apache Server version: Apache/2.4.6.

    can you help how is this possible …

    • Ravi Saive says:

      @Umesh,

      Simple, install CentOS 7.2 with LAMP stack and move the whole application and database (copy db from old machine and create a database and dump it on new machine) do a required MySQL settings in config file of application.

  3. Aamnah says:

    Just FYI, when generating SSH key, defining -b 2048 is a bit redundant since 2048 is the default bits for type RSA. ssh-keygen -t rsa is sufficient, one less thing to remember..

  4. Djez says:

    Hi Ravi,

    Nice tutorial, thanks a lot.

    The only manual operation in that case would be the dns change of the main server to the backup webserver.

    Is there a way or a solution to do this automatically? And how to switch back from backup to main when this one comes back up ?

    • Ravi Saive says:

      @Djez,

      Unfortunately, you have to manually make the IP switch in DNS when the master goes down or vice-versa, no automation options for this.

      • djez says:

        Hi ravi, thanks for the answer, this is what I was thinking.
        again thank you for the tutorial.

        • Alex says:

          There is a solution. I use keepalived to keep servers highly available. Once configured on both servers, point your DNS to the floating IP. If one dies, the other takes over.

  5. GustavoChalco says:

    One question, what should I do with the user that I already created. In your crond its root who connect to the other server… :/

    • Ravi Saive says:

      @Gustavo,

      You can use those newly created users to use for syncing files between two servers, as in my example I used root users to sync..

      • GustavoChalco says:

        That’s what I mean, for example if I want to sync Apache conf dir for bk, I need root privileges on the other server am right?

        -PS.
        Sorry for my bad english…

        • Ravi Saive says:

          @Gustavo,

          That’s right, you need root privileges to sync core system files, normal users don’t have such privileges to copy/sync system configuration files..

  6. Nacho says:

    Thank you. I use Rsync to replicate between one web server and two slaves for balancing and works perfect. thank you for share. greetings from Argentina.

  7. Ranjan says:

    Hello,
    How backup server will handle traffic if first server will down? rsync command only sync to data from one to another. but how it will handle the traffic just need to know

  8. @ndres says:

    What about Data Base replication? Nowadays most web sites uses databases.

  9. banker says:

    use KrojamSoft SyncFile it’s the best…

  10. Vlad says:

    I’m new to this. So apologize in advance for basic, dumb questions. Where do I enter these commands? Please give me specific steps. Do I have to login to my cpanel or WHM? Or is it something I can pull up from the FTP? Thanks in advance for your patience with my ignorant questions.

    • Ravi Saive says:

      The commands can be run on server level with direct root access. It will won’t work uner cpanel or WHM.

    • Marin Todorov says:

      Please submit your question in http://linuxsay.com forum with your specific needs and we will be more than glad to hep you with that. I am asking to submit the question in there as this is the official TecMint support forum and we will be able to provide more detailed instructions in there.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *