Daily backup of local git changes

While working on a ticket and not ready to commit, it’s a good idea to backup all of our changes to an archive file.

The following script does all that and executed daily by cronjob automatically.

  1. create a file, say “backup” in /etc/cron.daily
  2. Type the following (change ‘‘ to your own login name and to the git directory where source codes are located):
backing up changed files to tarball
LIST=`git status --porcelain | sed -n -e '/^ [D|M]/p' | sed -e 's/^ [D|M] //'`
backupname=`git branch | sed -n -e "/^* /p" | sed  -e 's/** //'`
backupname=$backupname-`date "+%s"`.backup.tar.bz2
if [ ! -d "$dest" ]
    mkdir -p $dest
tar jcvf $dest/$backupname $LIST > /dev/null

Make the file executable:

chmod +x /etc/cron.daily/backup

About The Seeker

Silicon Forest
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s