Created
June 25, 2020 10:47
-
-
Save burasuk/2956fd2a972fbf0e2a7431ba5ffe20c7 to your computer and use it in GitHub Desktop.
simple differential backup based on tar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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