Skip to content
wordpress meta

title: 'restic set tags'
date: '2019-11-23T07:11:39-06:00'
status: publish
permalink: /restic-set-tags
author: admin
excerpt: ''
type: post
id: 1427
category:
    - Backups
    - restic
tag: []
post_format: []

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.

```bash

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_tag echo backup policy: $tag

source /root/.restic.env

snapshotids=$(restic snapshots -c | egrep -v ID|snapshots|-- | awk '//{print $1;}') for snapshotid in $snapshotids do 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 $snapshotid done ````

Run

```bash

./backup-tags-set.sh

backup policy: daily Making a tag for: 0b88eefa - 2019-03-27 - Wed - daily repository 00cde088 opened successfully, password is correct create exclusive lock for repository modified tags on 1 snapshots Making a tag for: d76811ac - 2019-03-27 - Wed - daily repository 00cde088 opened successfully, password is correct create exclusive lock for repository modified tags on 1 snapshots ````