Skip to content

Instantly share code, notes, and snippets.

@barmic
Created April 13, 2020 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barmic/faa07632b99b448ffe2a37fefffff3d9 to your computer and use it in GitHub Desktop.
Save barmic/faa07632b99b448ffe2a37fefffff3d9 to your computer and use it in GitHub Desktop.
Tarsnap config
#!/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