Skip to content

Instantly share code, notes, and snippets.

@coffeeaddict
Created January 30, 2012 07:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coffeeaddict/1703075 to your computer and use it in GitHub Desktop.
Save coffeeaddict/1703075 to your computer and use it in GitHub Desktop.
My backup solution
#!/bin/sh
for file in $*
do
path=`dirname $file`
name=`basename $file`
if [ `printf "%.1s" $path` = "/" ]
then
echo "Files must be specified relative: $file"
exit 1
elif [ `printf "%.1s" $path` = "." ]
then
path=""
else
path="/$path"
fi
bu_path="backup$path"
bu_file="$bu_path/$name.`date +%Y%m%d`"
if [ ! -d $bu_path ]
then
echo "Creating $bu_path"
mkdir -p "$bu_path"
fi
if [ -f $bu_file ] || [ -f "$bu_file.0" ]
then
inc=1
if [ ! -f "$bu_file.0" ]
then
mv $bu_file "$bu_file.0"
fi
while [ -f "$bu_file.$inc" ]
do
inc=$((inc + 1))
done
bu_file="$bu_file.$inc"
fi
echo "$file => $bu_file"
cp -pr $file $bu_file
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment