diff --git a/backup_cosmicvoyage b/backup_cosmicvoyage index eb86360..53f7efb 100755 --- a/backup_cosmicvoyage +++ b/backup_cosmicvoyage @@ -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