Skip to content

Instantly share code, notes, and snippets.

@stv0g
Last active August 1, 2017 00:25
Show Gist options
  • Save stv0g/79b27c52149f98104ea6c0cab3628f9a to your computer and use it in GitHub Desktop.
Save stv0g/79b27c52149f98104ea6c0cab3628f9a to your computer and use it in GitHub Desktop.
Check if a new backup should be triggered

This script can be added to your bash startup script in order to remind you to do weekly / daily backups.

#!/bin/bash
export RESTIC_PASSWORD=$(pass restic)
TIMESPAN="1 week ago"
DIR="/Users/stv0g"
ATLEAST=$(date --iso-8601=ns --date "${TIMESPAN}")
ALL=$(restic snapshots --json)
LAST=$(echo "${ALL}" | jq -r "map(select(.paths[] | contains (\"${DIR}\"))) | sort_by(.time) | .[1]")
TIME=$(echo "${LAST}" | jq -r ".time")
if [[ "${TIME}" < "${ATLEAST}" ]]; then
echo "You should to do a backup!"
echo "Last backup of ${DIR} was made on ${TIME} which is more than ${TIMESPAN}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment