Created
December 31, 2014 14:23
-
-
Save heavenshell/9ab61e5db43446daff7a to your computer and use it in GitHub Desktop.
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 | |
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 |
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
$ bash backup.sh sample.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment