Skip to content

Instantly share code, notes, and snippets.

@heavenshell
Created December 31, 2014 14:23
Show Gist options
  • Save heavenshell/9ab61e5db43446daff7a to your computer and use it in GitHub Desktop.
Save heavenshell/9ab61e5db43446daff7a to your computer and use it in GitHub Desktop.
#!/bin/sh
TSTAMP=`date +%Y%m%d-%H:%M:%S`
FILENAME=$1
LOGPATH=$2
Rotate=3
logfile=backup.log-`date +%Y%m%d`
echo ".............Backup Script Running on $TSTAMP............" >> $logfile
let i=$Rotate-1
if [ -f "$FILENAME.$Rotate" ];then
echo "$FILENAME.$Rotate Found,Deleting" >> $logfile
rm -rf $FILENAME.$Rotate
else
echo "$FILENAME.$Rotate Not Found, Not Removing" >> $logfile
fi
while [ $i -ge 1 ]
do
let j=$i+1;
if [ -f "$FILENAME.$i" ];then
echo $FILENAME.$i exists and is being moved to $FILENAME.$j >> $logfile
mv $FILENAME.$i $FILENAME.$j
else
echo $FILENAME.$i not found, not moving to $FILENAME.$j >> $logfile
fi
let i=$i-1
done
cp $FILENAME $FILENAME.1
$ bash backup.sh sample.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment