Thursday, December 3, 2009

Using rsync on local folders

This command line synchronizes the 'test' folder with production folder, as simple deploy system. It uses the popular command 'rsync':
rsync -crv --delete --stats --exclude "*smarty*" test/www/ www/

It excludes smarty folder contents as is mostly used for auto-generated compiled templates.
On rsync command, it doesn't use the common -a (archive) flag as it tryes to maintain date and time from old files, and some servers don't let it and provoke a warning when syncing.
'--delete' is a potencially dangerous flag, that erases existing files if they are different than source ones.
Other interesting flag is -n, that performs a "dry run" that shows the results without perform the copy.