Skip to content

Instantly share code, notes, and snippets.

@burasuk
Created June 25, 2020 10:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save burasuk/2956fd2a972fbf0e2a7431ba5ffe20c7 to your computer and use it in GitHub Desktop.
Save burasuk/2956fd2a972fbf0e2a7431ba5ffe20c7 to your computer and use it in GitHub Desktop.
simple differential backup based on tar
#!/bin/sh
DATE=`date +%Y-%m-%d__%H-%M`
BACKUP_NAME=$DATE.tar.gz
DIR_TO_BACKUP='dir/to/backup'
# next differential backup
tar -czg snapshot.snar -f $BACKUP_NAME $DIR_TO_BACKUP
#!/bin/sh
# Run this file only once
BACKUP_NAME=full.tar.gz
DIR_TO_BACKUP='dir/to/backup'
# first full backup
tar -czg snapshot.snar -f $BACKUP_NAME $DIR_TO_BACKUP
cp snapshot.snar snapshot.snar.bak
#!/bin/sh
# Use:
# to restore directory do date `2020-06-25__11-18` :
# ./restore.sh -d 2020-06-25__11-18
# date format see file backup.sh line 3
#
# get date from CLI
DATE=
while getopts d: option
do
case "${option}"
in
d) DATE=${OPTARG};;
esac
done
# restore full backup first
tar -xzpf full.tar.gz
# loop thru files with incremental backups
for FILE in `find . -name "*.tar.gz" ! -name "full.tar.gz" -type f -printf "%f\n" | sort -n`
do
tar --incremental -xzpf ${FILE}
if [ $DATE'.tar.gz' = $FILE ]
then
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment