Sync live sites to in-house dev servers

One of our customer found it tedious to sync his live websites to his dev servers, it involved using FTP (since he had no version control) as well as the database.
The files were over 2GB by themselves, so it could be a time consuming task. As a result he asked us for a solution, and we were able to provide the following script to help him out.

Put the following into a script (eg ), then chmod +x

# Add your ssh key to the remote server before running this
# Where are the local files going to be saved
# No trailing / please on this one below
# Remote MySQL connection details
# Local MySQL connection details
# Remote host IP
rsync -avP ${REMOTE_USER}@${REMOTE_HOST}:/tmp/${REMOTE_SQL_DB}.sql /tmp/

Edit the script as needed to reflect the database/files/etc you want, then run ./

To make this really seamless, use ssh keys to login. If you want to have this on a cron, make sure you put the full path to the rsync and mysql, or any other binaries used.

This entry was posted in HOWTO. Bookmark the permalink.

One Response to Sync live sites to in-house dev servers

  1. Peter Bryant says:

    Bonus points to the developers that use a version control system (svn/git/etc) to do this. Keep the config files separate. Check in. Check out. Revert on errors. Revert to a particular code version for testing.

Leave a Reply

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

× 9 = nine

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>