Skip to content

Instantly share code, notes, and snippets.

@neilbutterworth
Created December 13, 2012 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilbutterworth/4277261 to your computer and use it in GitHub Desktop.
Save neilbutterworth/4277261 to your computer and use it in GitHub Desktop.
my little backup script
#!bash
# backup directories listed in the .backup file of the user's home directory
# if the directory contains a makefile, run make clean to scrub any object
# and/or executable files that don't need backup
#
# backup is placed in a a dated zip archive - copying to removable media
# is not performed
# Copyright (C) 2008 Neil Butterworth
#set -x
# report error and quit
error() {
echo "ERROR: $*"
exit 1
}
# we need a .backup file in the users home dir
if [ ! -f ~/.backup ]
then
error "No .backup file in home directory"
fi
# zip tool and zip output name
ZIPPER="C:/Program Files/7-Zip/7z.exe"
ARCHIVE=~/backup-`date -I`.7z
# existing archive probably means last backup failed
echo "Archive name will be $ARCHIVE"
if [ -f "$ARCHIVE" ]
then
echo "Removing existing archive"
fi
rm -f "$ARCHIVE"
# read the .backup file which simply contains a list of directories
# to back up recursively using a zip program
while read DIRNAME
do
# ignore blank lines
if [ "$DIRNAME" = "" ]
then
continue
fi
# report missing directory and carry on
if [ ! -d "$DIRNAME" ]
then
echo "No such director as $DIRNAME - skipping"
continue
fi
# possibly clean directory, then zip it
pushd $DIRNAME > /dev/null
if [ -f Makefile ]
then
make clean > /dev/null
fi
popd > /dev/null
echo "adding $DIRNAME to $ARCHIVE ..."
if "$ZIPPER" a -r "$ARCHIVE" "$DIRNAME" > /dev/null
then
echo "added ok"
else
error "backup failed"
fi
done < ~/.backup
# that's all folks
echo "completed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment