Created
January 30, 2012 07:38
-
-
Save coffeeaddict/1703075 to your computer and use it in GitHub Desktop.
My backup solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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