sync-files is a tool for logging into a number of remote machines, executing commands and copying files. It can be used to copy or synchronize files and directories from one environment to another with a single command line.
Rather than using FTP or some other form of file transfer, sync-files uses ssh to execute commands on remote machines and rsync to copy only the diffs of files that have actually changed. Only actual changed pieces of files are transferred, rather than the whole file, which results in transferring only a small amount of data. The tiny pieces of diffs are then compressed on the fly, further saving you file transfer time and reducing the load on the network.
| Option | Description |
|---|---|
| <sync-files> create-dir | This option creates the deployment directory structure. |
| <sync-files> create-ssh-key | This option creates an SSH key on the remote hosts. |
| <sync-files> -e | This option defines the environment (eg: dev, stg, prd) when performing a deployment. |
| <sync-files> -h | This option prints a short help page describing the options available in sync-files. |
The project directory represents your project's root directory:
var/
www/
project/
src/
To prepare your project for deployment, start up your terminal application and go into the root directory of your project:
$ cd /var/www/project
Inside this projects directory, execute the following command:
$ /path/to/sync-files.sh -e dev create-dir
This will create a deploy directory and the given environment directory:
var/
www/
project/
deploy/
env/
dev/
log/
src/
To add a new environment:$ /path/to/sync-files.sh -e prd create-dir
Users can override global settings by placing configuration files in the project/deploy/env/<env> directory. For instance, you might need to do this to change the list of remote hosts:
sync.hosts
deploy/env/dev/sync.hosts
username@dev01.host.com username@dev02.host.com
sync.path
deploy/env/dev/sync.path
SOURCE_DIR="/var/www/project/src/" TARGET_DIR="/var/www/project"
This will copy the files from: /var/www/project/src/ to: username@dev01.host.com:/var/www/project and username@dev02.host.com:/var/www/project:
sync.exclude
deploy/env/dev/sync.exclude
*~ _* .svn
Each line can contain a file, a directory or a pattern.
sync.prehook
deploy/env/dev/sync.prehook
cd /var/backup tar -cvf project-backup.tar.gz /var/www/project echo "done"
sync-files uses public-key cryptography and SSH to authenticate you during the transfer of files and execution of commands. In order for the remote servers to identify you, you must provide them with your SSH public key.
To create an SSH key on the development environment (if you don’t already have one) you need to execute the following command:
$ sync-files -e dev create-ssh-key
It is important to hit ENTER when prompted for a passphrase. Otherwise the passphrase that you enter will be requested from you every time you connect to a remote host.