#! /bin/bash # # backup cosmicvoyage files to a dir in your homedir # # put it into your crontab # 0 22 * * * $HOME/bin/backup_cosmicvoyage # # alexlehm@cosmic.voyage # SHIPS=~/ships BACKUP=~/backup-ships test -d $SHIPS || (echo "ships does not exit" ; exit 1) test -d $BACKUP || mkdir $BACKUP OLDBACKUP=$(find $BACKUP -name "ships-*.tar.gz" -print|sort|tail -1) cd $SHIPS || exit 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" # have to use */* since it would otherwise backup the symlinks and not # the target, maybe we could use an option in tar otherwise tar cvfz "$TGZ" ./*/* ./*/.??* # don't keep backup file if nothing has changed if [ -f "$OLDBACKUP" ] && cmp -s "$OLDBACKUP" "$TGZ" then echo "nothing has changed, no new backup" rm -f "$TGZ" else echo "file is different, keeping new file" fi test -f "$TGZ" && echo "backup of file $TGZ was successful"