While working on special projects for Felthos Foundry that will be revealed in the near future, I found developing only on the QA Server a bit cumbersome as the connection was not always quick and I could not completely modify the QA site as needed.

Realizing the limitations, I brought the code back to my personal development machine which happens to be a Mac. This decision works from a engineering standpoint, but the code was not available to my padna, I could not easily access the code from outside my house and now the company must rely that I make backups of the code.

To address the concerns of backups and remove access to the files by myself and my padna, I wrote a quick little script with rsync. Rsync is an open source utility the provides quick incremental file transfer and is available under the GNU General Public License. Rsync typically comes packaged on most linux distros and OS X had it pre-installed.

In order to treat my development machine as the master for the syncing relationship and the QA server as a slave, the following conditions must be met:

  1. File modified or created on the Development machine will be modified or created on the QA Server;
  2. Files should be deleted on the QA Server that are no longer on the Development machine;
  3. If a file has been modified on the QA Server, the modified file will be synced back to my Development machine.

With that in mind, here’s the script:


#!/bin/bash

logfile=”/path/to/backup.log”

src=”/path/to/development/machines/directory”
dest=”user@fqdn:/path/to/QA/directory”
opt=”-azu –delete -v –exclude ‘._.DS_Store’”

echo”" >> $logfile; echo “Backup: iMac->QA” >> $logfile

rsync $opt “$src” “$dest” >> $logfile

src=”user@fqdn:/path/to/QA/directory”
dest=”/path/to/development/machines/directory”
opt=”-az –exclude ‘._.DS_Store’”

echo”" >> $logfile; echo “Backup: QA->iMac” >> $logfile

rsync $opt “$src” “$dest” >> $logfile
The variables that need to be modified include the logfile, src, dest and opt (src, dest, and opt in two places). The logfile is the path and filename for where all output will be stored during the rsync. The first src is the path on the development machine that needs to be synced while the dest includes the username, fully qualified domain name and path to the destination directory on the QA Server. Finally, the first opt variable should include the options required to sync files from the development machine to the QA Server. In this case, a represents archive, z represents compressed, –delete represents deleting files in the destination that are no longer in the source, and the exclude statement stops the syncing of a Mac specific filename.

The second set of variables for src and dest are basically the exact opposite of the first set. The src in the second case changes to the QA Server while the dest is the development machine. The second opt should not include the –delete command.

While the script performs transfers incrementally and the script and process are simple, I’d suggest performing a trial run with just a couple of small files as the first sync could saturate your network connection.

Technorati Tags: , ,