In a follow up to previous post https://blog.ls-al.com/restic-create-backup-and-set-tag-with-date-logic here is some code I used to set tags on old snapshots to comply with my new tagging and pruning.
# cat backup-tags-set.sh#!/bin/bash
create_tag () { tag="daily" if [ $(date -d "$1" +%a) == "Sun" ]; then tag="weekly" ; fi if [ $(date -d "$1" +%d) == "01" ]; then tag="monthly" if [ $(date -d "$1" +%b) == "Jan" ]; then tag="yearly" fi fi}create_tagecho "backup policy: " $tag
#source /root/.restic.envsnapshotids=$(restic snapshots -c | egrep -v "ID|snapshots|--" | awk '//{print $1;}')for snapshotid in $snapshotidsdo snapdate=$(restic snapshots $snapshotid -c | egrep -v "ID|snapshots|--" | awk '//{print $2;}') create_tag $snapdate echo "Making a tag for: $snapshotid - $snapdate - $(date -d $snapdate +%a) - $tag" restic tag --set $tag $snapshotiddone
# ./backup-tags-set.shbackup policy: dailyMaking a tag for: 0b88eefa - 2019-03-27 - Wed - dailyrepository 00cde088 opened successfully, password is correctcreate exclusive lock for repositorymodified tags on 1 snapshotsMaking a tag for: d76811ac - 2019-03-27 - Wed - dailyrepository 00cde088 opened successfully, password is correctcreate exclusive lock for repositorymodified tags on 1 snapshots