Skip to content

Instantly share code, notes, and snippets.

@mitio
Created September 26, 2011 22:42
Show Gist options
  • Save mitio/1243623 to your computer and use it in GitHub Desktop.
Save mitio/1243623 to your computer and use it in GitHub Desktop.
Simple backup and versioning script for novice Windows users. Uses Git for Windows.
# The only required setting is DATA_ROOT. It must be a valid
# Git repository (git init'ed). You need to configure a name
# and an email to be used as commit author info. You also need
# to configure a remote named "origin" for this repository.
# A branch "master" is assumed to exist. For repositories with
# large binary files, you may want to change the following Git
# settings (probably only locally, for the current repo):
#
# core.autocrlf=false
# core.compression=0
# core.loosecompression=0
# pack.compression=0
# pack.window=0
#
# If you've just set up Git, don't forget to set the committer info:
#
# git config --global --add user.name "Some One"
# git config --global --add user.email [email protected]
#
# On Windows, using MSysGit (Git for Windows):
# * Copy the "Git Bash" shortcut somewhere
# * Edit the "Target" property of the shortcut and paste the following:
# C:\Windows\SysWOW64\cmd.exe /c ""C:\Program Files (x86)\Git\bin\sh.exe" --login -c '/C/Data/backup.sh'"
# * Just be sure to modify the "/C/Data/backup.sh" script to ensure
# it points to the location where you've saved this file
#
# You may want to make the same settings at the remote repo too.
# Happy backing up!
#
# Author: Dimitar Dimitrov <[email protected]>
# License: MIT
DATA_ROOT="/C/Data"
echo -e "\n\nBacking up $DATA_ROOT..."
result=1
if cd $DATA_ROOT && git add .
then
status=`git status --porcelain`
if [ $? = 0 ]
then
if [ "$status" = "" ]
then
result=0
echo "Nothing to backup. No changes."
else
echo "Changes detected, adding to backup..."
git commit -a -m "Changes at `date +'%Y-%m-%d %H:%M'`" && \
echo "Files added to backup, sending data to backup server..." && \
git push origin master
result=$?
fi
else
echo "ERROR: Cannot check files for modifications (git status has failed)."
fi
else
echo "ERROR: Cannot add changed files to the backup (git add has failed)."
fi
if [ $result = 0 ]
then
echo "All done."
else
echo "BACKUP FAILED. An error has occurred ($result)."
fi
echo "Press any key to exit..."
read
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment