If you run a critical website, it is a good practice to mirror your files to a secondary server. In the event that your main server has a network or hardware issue, having mirrored files provides you with the flexibility to immediately switch from one server to another.<\/p>\n
To sync your files from server\u00a0A (main)<\/strong>\u00a0to server\u00a0B (backup)<\/strong>, follow these steps.<\/p>\n Install rsync on both server A and server B.<\/p>\n Run the following command on server B to generate an SSH key.<\/p>\n Press enter to skip all inputs.<\/p>\n Copy the content generated in\u00a0 Go to server A<\/strong>, insert the copied content into\u00a0 If this directory or file does not exist, create it. Now server B can log into server A using SSH.<\/p>\n Go back to server B and start rsync for the first time. Review and run the command below. You will need to add the path to your website on both servers and the IP address of server A.<\/p>\n Type\u00a0 Setup a cronjob to sync your files automatically. This example syncs them every 3 minutes. Edit\u00a0 Review the following line, and append it in the\u00a0Install rsync<\/strong><\/h3>\n
apt-get install rsync\r\n<\/code><\/pre>\n
Generate an SSH key on server B<\/strong><\/h3>\n
ssh-keygen\r\n<\/code><\/pre>\n
\/root\/.ssh\/id_rsa.pub<\/code>.<\/p>\n
Insert the SSH public key to server A<\/strong><\/h3>\n
\/root\/.ssh\/authorized_keys<\/code>.<\/p>\n
Start sync<\/strong><\/h3>\n
rsync -avrt --delete --rsh='ssh -p 22' root@SERVER_A_IP_ADDRESS:\/path\/to\/your\/website\/in\/server\/a\/ \/backup\/path\/in\/server\/b\/\r\n<\/code><\/pre>\n
yes<\/code>\u00a0if you been asked to save the authentication information. If you have configured ssh to listen on a custom port, change the 22 to your own port. Wait until all files has been synced over.<\/p>\n
Setup cronjob<\/strong><\/h3>\n
\/etc\/crontab<\/code>.<\/p>\n
crontab<\/code>\u00a0file. You will need to update it as you did previously.<\/p>\n
*\/3 * * * * root rsync -avrt --delete --rsh='ssh -p 22' root@SERVER_A_IP_ADDRESS:\/path\/to\/your\/website\/in\/server\/a\/ \/backup\/path\/in\/server\/b\/ >\/dev\/null 2>&1<\/code><\/pre>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","manualknowledgebasecat":[233,242,247],"manual_kb_tag":[303],"_links":{"self":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2468"}],"collection":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/comments?post=2468"}],"version-history":[{"count":1,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2468\/revisions"}],"predecessor-version":[{"id":2469,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2468\/revisions\/2469"}],"wp:attachment":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/media?parent=2468"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manualknowledgebasecat?post=2468"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb_tag?post=2468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}