Created
April 13, 2020 14:25
-
-
Save barmic/faa07632b99b448ffe2a37fefffff3d9 to your computer and use it in GitHub Desktop.
Tarsnap config
This file contains hidden or 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/bash | |
# install in /etc/NetworkManager/dispatcher.d/02tarsnap | |
IF=$1 | |
STATUS=$2 | |
RETENTION_DAYS=7 | |
RETENTION_COUNT=5 | |
[[ "$STATUS" != 'up' ]] && exit | |
logger -s "NM Script up triggered $USER" | |
backups=$(mktemp) | |
tarsnap --list-archives > "${backups}" | |
grep -qF "$(uname -n)-$(date +%Y-%m-%d)" "${backups}" && exit | |
name="$(uname -n)-$(date +%Y-%m-%d_%H-%M-%S)" | |
logger -s "Create backup ${name}" | |
sudo tarsnap -cf "${name}" /home/michel | |
TIMESTAMP_RETENTION=$(( $(date '+%s') - (86400*$RETENTION_DAYS) )) | |
filter() { | |
now=$(date '+%s') | |
while read ; do | |
current_backup=$(date -d$(echo "$REPLY" | sed 's/MBA-viseo-\(.*\)_.*/\1/') '+%s') | |
[[ $now -gt $current_backup ]] && echo "$REPLY" | |
done | |
} | |
sort -r "${backups}" | awk "NR>${RETENTION_COUNT}" | filter | xargs -n1 tarsnap -df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment