delete backup file if it is the same as the last one to avoid writing a file
when no files have changed on a daily backup
This commit is contained in:
parent
1a307666e8
commit
02765c2c37
|
@ -7,15 +7,40 @@ test -d $SHIPS || (echo "ships does not exit" ; exit 1)
|
|||
|
||||
test -d $BACKUP || mkdir $BACKUP
|
||||
|
||||
OLDBACKUP=`ls -1 $BACKUP/ships-*.tar.gz 2>/dev/null|tail -1`
|
||||
|
||||
cd $SHIPS
|
||||
|
||||
TS=`date -u +%Y-%m-%dZ%H:%M`
|
||||
|
||||
TGZ="$BACKUP/ships-$TS.tar.gz"
|
||||
|
||||
echo backing up $SHIPS to $TGZ
|
||||
# if you run the script more than once within 1 minute it gets
|
||||
# confused
|
||||
|
||||
if [ -f $TGZ ]
|
||||
then
|
||||
echo backup file $TGZ already exists, not overwriting
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
echo "backing up $SHIPS/* to $TGZ"
|
||||
|
||||
tar cvfz $TGZ */*.txt */LICENSE
|
||||
|
||||
# don't keep backup file if nothing has changed
|
||||
|
||||
if [ -f "$OLDBACKUP" ]
|
||||
then
|
||||
if cmp -s "$OLDACKUP" $TGZ
|
||||
then
|
||||
echo "file is different, keeping new file"
|
||||
else
|
||||
echo "nothing has changed, no new backup"
|
||||
rm -f $TGZ
|
||||
fi
|
||||
fi
|
||||
|
||||
test -f $TGZ && echo backup of file $TGZ was successful
|
||||
|
||||
|
|
Loading…
Reference in New Issue