Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Simple rsync backup script written in Ruby
Pull request Compare This branch is even with RichGuk:master.
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


RRSync (Ruby RSync)

RRsync is a Rsync backup script that's written in Ruby. It performs the simple operation of syncing the contents of a given folder to a remote location via SSH. The script allows you to control the level of output (log files, screen output) , it is ideal for calling from a cron or launchd.

The backups are structured as such:

/remote/location/current - The current folder contains the the latest clone of the intended backup folder.
/remote/location/backup_dir - The backup directory, which by default is the current day (monday, tuesday, etc) contains the difference to current since it was last run. So it will contain any new files, any files that were deleted.

NOTICE: I take no responsibility for any data loss, so please test before using with test data!!!!!

Please feel free to contribute to this script and I'll accept any changes for the good.

== How to install

A few things are required for this script to function correctly.
	* Ruby 1.8.x
	* rsync 3.0.x
	* ssh command
Rsync on OS X 10.5:

On OS X 10.5 the default rsync is out of date and missing a few used options you may use macports to install the latest.
	sudo port install rsync
To install the script simply copy it to where ever you wish to run the script from. Make sure its executable by issuing the following:

	sudo chmod 755 rrsync.rb

== How to use

You may run the script by issuing the following command:

	ruby rrsync.rb
or (providing it has execute permissions)

See examples/ for examples of crontab and launchd settings.	

= Configuration options

This is the command to use for ssh, full path should not be needed but might be wise.

This is the command to use for rsync, full path should not be needed but might be wise.

This is the location of a file which contents of files and directories to exclude from the backup.

The file should be formatted with each file or directory on it's own line. The list needs to be relative to DIR_TO_BACKUP.

This is the location folder you wish to backup to a remote machine for example: /Users/foo

If you wish to have the contents of the remote backup like /remote/backup/documents instead of /remote/backup/foo/documents then you need to add a trailing slash to this command, for example: /Users/foo/

This is the location to put the log file, if you wish not to create a log file you may leave this blank. You can also achieve this with the SLIENT option (see below for more details).

This is how long to keep log files for you can supply daily, weekly or monthly here.

This is NEEDED to clean out the previous weeks backup folder. The script will create the folder and delete it after.

You can choose the location of this folder (needs write permission), the default of /tmp/empty_dir is normally OK.

The ssh user you wish to use for the remote machine example: rich would be turned into rich@SSH_SERVER.

The hostname or ip of the remote machine where the backups are copied too for example: would be turned into SSH_USER@

If you run ssh on a non-standard port you may supply that here.

This is the location to store the backups on the remote machine. You  do not need to add the current or BACKUP_DIR part, example: /media/backups/macbook

This can normally be left as default. This controls where to put the differences to current by default this is monday, tuesday, etc...

This allows you to control how much output rsync gives, this does not effect if logs are produced (see SLIENT and DEBUG) you may use: --progress, -v, -vv, -vvv here to give different levels of output (note: --progress may clutter the logs)

This can normally be left as default. Change this if you know what you're doing this allows you to change the options that are passed to rsync (see man rsync).

If enabled then output will be shown to the screen and will NOT be outputed to the log file. This is useful for testing and debugging any problems you might have.

This can be either: true or false

If you wish to have no output at all (screen and log files) then set this to true.

This can be either: true or false


== Pitfalls 

	* This is not supported on WINDOWS! I don't think it will work at all!
	* Only supports SSH as the transfer protocol
	* Doesn't allow much in the way of the default directory structure of current folder and a backup (normally monday, tuesday, etc)
== Contact/contribute

Feel free to fork and send me pull requests I will most likely merge the changes into the main repo.

You can contact me at or drop me an email at rich -at-

Something went wrong with that request. Please try again.