Question

Is there a way to sync the images folder between my live server and the staging server? so when a new image is added to the live server it would be copied automatically to the staging.

Im currently on rackspace servers "both of them".

Was it helpful?

Solution

You haven't mentioned what operating system you're using, or how immediate you want this to happen. I would look into using rsync. Set up login using ssh key authentication (instead of password), and add a cron job that runs it regularly.

On live, as the user that does the copying run this command:

ssh-keygen

(Leave the passphrase empty).

Next copy the public key to the staging server (make sure you don't overwrite existing authorized_keys file, if it already exists you have to append id_rsa.pub to that file):

scp ~/.ssh/id_rsa.pub staging-server:.ssh/authorized_keys

Finally set up the cron-job:

echo '15,45 * * * * rsync -avz -e ssh /path/to/images staging-server:/path/to' | crontab -

This runs your script quarter past and quarter to every hour. For more info on the cron format, see the appropriate man page:

man 5 crontab

To understand the rsync options, check the rsync manpage. This command won't remove images on staging when you remove images on your live server, but there are options for that.

Also, remember to run the command manually once as the user in question, to accept ssh server keys and make sure key auth is working.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top