{"id":718,"date":"2007-05-06T19:00:26","date_gmt":"2007-05-06T12:00:26","guid":{"rendered":"http:\/\/www.jfdesignnet.com\/?p=718"},"modified":"2007-05-06T19:00:26","modified_gmt":"2007-05-06T12:00:26","slug":"using-rsync-to-mirror-data","status":"publish","type":"post","link":"https:\/\/www.jfdesignnet.com\/?p=718","title":{"rendered":"Using rsync to mirror data"},"content":{"rendered":"<p><strong>Introduction<\/strong><br \/>\nThis LinuxAnswer describes how to mirror 2 systems using rsync over ssh.<br \/>\nI 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.<\/p>\n<p><strong>Assumptions<\/strong><br \/>\n1) You know how to open up a terminal and type a few basic commands.<br \/>\n2) You already have a working ssh server and client installed.<br \/>\n3) You have private\/public keys generated to allow password less logins  to the live server form the backup server.  If not then see this <a href=\"http:\/\/www.jfdesignnet.com\/?p=713\">article<\/a>.  In relation that how to the backup server  is the client and the live server is the server.<\/p>\n<p><strong>Why would you want to?<\/strong><br \/>\nThere are many reasons so I&#8217;ll just list a few:<br \/>\n1) Data transfer is fast as rsync only copies modified files<br \/>\n2) Running it over ssh encrypts the data transfer so it is more secure  than other methods<\/p>\n<p><strong>The real howto<\/strong><br \/>\n1) Decide on the directories you need to backup on the live server  assuming it is a webserver this may be &#8220;\/home\/httpd&#8221;<br \/>\n2) Decide on the options you want.  The most common I would use are:<br \/>\n<strong>-a<\/strong> Archive mode this is a combination of &#8220;-rlptgoD&#8221; basically it  works recursively and maintains file information such as creation dates,  permissions etc. See the man page for detailed info.<br \/>\n<strong>-v<\/strong> Increase the verbosity.  This will let you see what is  transferred<br \/>\n<strong>-z<\/strong> Compress data so that it is a quicker transfer<br \/>\n<strong>&#8211;delete-after<\/strong> Delete any files that have been deleted on the  live server<br \/>\n<strong>-e ssh<\/strong> Most importantly, run the transfer over an ssh connection<br \/>\nA full list can be obtains from &#8220;man rsync&#8221;.<br \/>\n3) Try a dry run on the backup server with &#8220;-n&#8221; to make sure any typos  don&#8217;t totally screw your system. This will just show what would be done:<br \/>\n<strong>rsync -e ssh -avzn &#8211;delete-after user@liveserver:\/home\/httpd \/home<\/strong><br \/>\n4) If everything went as expected you can give it a go without -n<br \/>\n<strong>rsync -e ssh -avz &#8211;delete-after user@liveserver:\/home\/httpd \/home<\/strong><br \/>\nYou should get the info about the files being transferred.  Running it  again should be quicker as very little has probably changed.<br \/>\n5) That should be it, just try creating and deleting a few files and run  rsync to make sure the changes occur<\/p>\n<p><strong>Automating the process<\/strong><br \/>\nThe obvious answer running the rsync commands on the backup server via  cron.<br \/>\nA basic example being to mirror every hour on the hour:<br \/>\n<strong>0 * * * * rsync -e ssh -avz user@liveserver:\/home\/httpd \/home  2&gt;&amp;1 &gt; \/var\/log\/hourly_backup.log<\/strong><br \/>\nThen remove deleted files every night:<br \/>\n<strong>30 0 * * * rsync -e ssh &#8211;delete-after -avz  user@liveserver:\/home\/httpd \/home 2&gt;&amp;1 &gt;  \/var\/log\/nightly_backup.log<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction 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. Assumptions 1) You know how to open up a terminal [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[150,201],"_links":{"self":[{"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=\/wp\/v2\/posts\/718"}],"collection":[{"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=718"}],"version-history":[{"count":0,"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=\/wp\/v2\/posts\/718\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=718"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=718"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jfdesignnet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}