47 lines
808 B
Bash
Executable File
47 lines
808 B
Bash
Executable File
#! /bin/bash
|
|
|
|
SHIPS=~/ships
|
|
BACKUP=~/backup-ships
|
|
|
|
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"
|
|
|
|
# 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
|
|
|