| Knowledgebase Home | Glossary | Favorites |
| Syncing files between multiple contianers. | ||||||||||
Table of Contents
1. The Rsync CommandSince we will be using rsync to sync files from one container to another we will need to use rsync with SSH. Rsync will be run from the container you wish to sync files to or the "slave container".rsync -avze ssh c-web1.wxyz.stackablehost.com:/remote/folder/ /local/folder/*note: use your "master" container hostname instead of c-web1.wxyz.stackablehost.com(this can be found on the Stackable panel) The command above inctructs rsync to ssh to the "master container", check the folder ~/sites/mystackable.com_env1/doc_root/ and ensure that the files in the local copy of that folder match the files on the "master container". In running this command we notice that it prompts for a password everytime. If we plan on having cron run this script for us automatically, prompting for a password is undesirable. 2. Generating a GPG key pairTo get around this we will utilize a feature of SSH that allows us to create a pair of keys that containers share. This will allow us to SSH without a password prompt.![]() First we will create the keys on the "slave container" and set-up the proper permissions. SSH to the "slave container" and run these commands: ssh-keygenPress enter at all 3 prompts to use defaults and no passphrase. chmod 700 ~/.ssh chmod go-rwx ~/.ssh/* 3. Sharing the key pairOnce the keypair is created we will need to share the public key (~/.ssh/id_rsa.pub) with the "master container"scp ~/.ssh/id_rsa.pub c-web1.wxyz.stackablehost.com:Now we will need to append the public key to a special file on the "master container". SSH to the "master container" and run these commands: if [ ! -d .ssh ]; then mkdir .ssh ; chmod 700 .ssh ; fi if [ ! -f authorized_keys ]; then touch authorized_keys ; chmod 600 authorized_keys ; fi cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys 4. Testing the key pairsNow we should be able to run rsync over ssh without a password prompt. From the "slave container run":rsync -avze ssh c-web1.wxyz.stackablehost.com:~/sites/mystackable.com_env1/doc_root/ ~/sites/mystackable.com_env1/doc_root/If everything worked correctly it should not for a password and tell you how much data was transferred. If it did not work check and make sure the permissions of the files are correct and that the the file authorized_keys is spelled correctly and is in ~/.ssh. 5. Configure the cron jobNow that we have verified that rsync works we can set-up a cron job. A cron job simply a way of telling Linux to run a certain command at a certain time. To set-up a cron job type on the "slave container":crontab -eNow we will need to tell crontab what to run and when to run it. To do this add a line like the following to the file. */5 * * * * rsync -avze ssh stackablehostname:/remote/directory /local/directory Once this line is added save and exit the file. This will tells cron to run the rsync command every 5 minutes. At this point, the "slave containers" are syncing with the "master containers" every 5 minutes! Now we just need to repeat this process for any other "slave containers" we have. |
| Visitor Comments |
|
| Related Articles |
| No related articles were found. |
| Attachments |
| No attachments were found. |