Tag disappears after a backup

I had a tag I manually added disappear after a backup. Is this a bug? Am I using restic wrong? (I haven’t used tags much before)

First, I added the tag:

$ restic snapshot
<...>
8b867a93  2024-10-07 16:42:28  macaw.local              /Users/ilyagr                                                     6.257 GiB
                                                        /etc
                                                        /private/etc
$  restic tag 8b867a93 --add wasteful
create exclusive lock for repository
repository e04784bb opened (version 2, compression level auto)
modified tags on 1 snapshots
$ restic snapsots
<...>
4a4eafd0  2024-10-07 16:42:28  macaw.local  wasteful    /Users/ilyagr                                                     6.257 GiB
                                                        /etc
                                                        /private/etc

So far, all is OK. The snapshot id changed, but that is expected (as I was just surprised to learn after browsing the forum). Now, I do a backup:

$ restic backup ... # Nothing about tags here
open repository
repository e04784bb opened (version 2, compression level auto)
using parent snapshot 8b867a93
load index files
<...>

This seems problematic already. Note the “using parent snapshot 8b867a93” line: it’s using the id from before the tag was added. Now, the older snapshot again has the id 8b867a93 and no tag:

$ restic snapshots # Shows the old snapshot without tag and the new one we just made
<...>
8b867a93  2024-10-07 16:42:28  macaw.local              /Users/ilyagr                                                     6.257 GiB
                                                        /etc
                                                        /private/etc

0d58b414  2024-10-08 18:38:55  macaw.local              /Users/ilyagr                                                     6.271 GiB
                                                        /etc
                                                        /private/etc

How do I add a tag so that it stays?

I’m using restic 0.17.1 compiled with go1.22.7 on darwin/arm64.

Update: Assuming the tag --add operation is meant to create a new snapshot 4a4eafd0 and delete the old snapshot 8b867a93, would this be what happens if the deletion is somehow prevented? I was copying the restic repo at the time to another dir, maybe the cp command prevented the deletion of the old snapshot by opening its file somehow and by a very unlikely coincidence.

It’s unclear from your question what actually happened. The “update” section indicates that the repository might have been locked and the tag --add operation was not successful. Normally, adding a tag to a snapshot should add this tag and change the snapshot ID. Tags are not copied (inherited) from parent snapshots. So new backups need the option --tag wasteful, too, if your intention is to tag them: restic backup --tag wasteful ….

I’m my first code snippet, I checked that the tag appears in the output of restic snapshots after the jj tag command. However, after I do another backup, there is no snapshot with that tag anymore. Instead, the snapshot that existed before the jj tag command is present again.

I didn’t show it, but I also tried jj snapshots --tag wasteful and it didn’t find anything.

I didn’t expect the new snapshot to have the tag, but I expected the older snapshot to still have it.

I’ve just tried a test with the same restic version and can’t reproduce. If you were accessing the repository out of band at the time this could have caused a problem in theory. Would you try again without anything else accessing the repository? Can you reproduce this with a new repository?

Would you try a restic check --read-data on the repository? What storage medium is the repository on? I’ve seen weird things like this with faulty SD cards.

OK, so at least I now know that wasn’t supposed to happen. Good!

I didn’t make a copy of the broken version of the repo. Now, restic check saw a lock, but worked fine after I unlocked the repo:

$ restic check --read-data -r .
using temporary cache in /var/folders/lj/rv4h95_d0mxb9ryztzpz4qph0000gn/T/restic-check-cache-3546843126
create exclusive lock for repository
repository e04784bb opened (version 2, compression level auto)
created new cache in /var/folders/lj/rv4h95_d0mxb9ryztzpz4qph0000gn/T/restic-check-cache-3546843126
repo already locked, waiting up to 0s for the lock
unable to create lock in backend: repository is already locked by PID 40791 on macaw.local by ilyagr (UID 501, GID 20)
lock was created at 2024-10-08 19:54:37 (15h17m22.494247s ago)
storage ID 3c3656ed
the `unlock` command can be used to remove stale locks

$  restic unlock  -r .
repository e04784bb opened (version 2, compression level auto)
successfully removed 1 locks

$ restic check --read-data -r .
..
create exclusive lock for repository
...
no errors were found

I guess I’ll see if it happens again.

1 Like