Skip to content
A simple ruby library for backing up files & directories to git
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Do you have backups of your production web/mail/db configs? crontabs?

How fast could you configure a production machine if everything was lost?

Gitback allows you to version arbitrary files and/or directories in a git repository. You just need to include the gem and write a brief ruby script that indicates the files/directories you'd like to backup. Then, run the script via cron. Gitback will take care of a adding/commiting/pushing whenever your files are modified.



$ gem install gitback


Here's a basic example of a script using gitback:

require 'rubygems'
require 'gitback' '/var/config-backup/' do |repo|
  repo.backup '/opt/nginx/conf/nginx.conf'
  repo.backup '/etc/mysql/'
  repo.backup '/etc/memcached.conf'
  repo.backup '/etc/ssh/sshd_config'
  repo.backup '/var/spool/cron/crontabs/'

This will check these files for additions/changes. If a file has been added or changed, gitback will commit it.

For example, the nginx config file would be saved to the following location:


Notice that '/etc/mysql' is a directory. Gitback accepts directories and will copy everything within that directory into the git repository.


Namespaces are also supported. If you'd like to use the same repository for multiple servers you can specify a namespace like this: '/var/config-backup/' do |repo|
  repo.namespace '' do
    repo.backup '/opt/nginx/conf/nginx.conf'

This will save the file to the following location:


Remote Git Repositories

Gitback is intended to be used with remote git repositories. If your git repository is tracking a remote branch, gitback will push changes to the remote after each commit.

Running Via Cron

There's nothing special about a gitback script. In order for it to backup your files you'll need to run it via the command line. I suggest setting up a cron job to do this for you at regular intervals.


Copyright (c) 2010 Bryce Thornton. See LICENSE for details.

Something went wrong with that request. Please try again.