Clever way to remove rewritten snapshots from Repo Copy

Hello,

I have a main restic repo and some secondary repos (which are sync using restic copy). When I change a snapshot using restic rewrite in the main repo, how can I accomplish that this snapshot is also rewritten in the secondary repos?

Does the naive approach to run the same rewrite command against the secondary repo work? I reckon that this does not work as restic remembers the snapshot id when copying a snapshot. So I suspect that this would lead to duplicated snapshots.

Currently my workaround is to use restic rewrite --forget ... > remove-snapshots and then grep for “saved new snapshot” and use those ids as input for restic forget. Finally I copy again all snapshots from the main to the secondary repo.

Is there any smarter way to do this?

Do you want both repos to be the same? Then I’d generally just rsync them.

Do you want both repos to be the same? Then I’d generally just rsync them.

Yes. But when I rewrite in the main repo the snapshot will (that’s what I expect) be duplicated. And as I also run restic forget with identical policies I don’t know what happens when both old and rewritten still snapshots exist.

The copy command won’t be able to determine that the rewritten snapshots in the primary and secondary repository match.

I’m not sure that does work. Snapshots in both repositories have different IDs, that is a snapshot ID from the primary repository shouldn’t exist in the secondary repository.

The result will be somewhat random, the forget command sorts snapshots by timestamps, which can’t work properly in case of a mix of original and rewritten snapshots.

The complete process is like follows:

  1. First run restic forget --forget with “some parameters” on the main repo
  2. Then run restic forget --forget > remove-snapshots on the secondary repo (obviously using the same parameters as in the previous command)
  3. grep "saved new snapshot" remove-snapshots
  4. Use the ids from the previous command as input for restic forget
  5. (At this point the secondary repo neither has the old rewritten snapshot nor the new rewritten snapshots, but the packs of both should be still there.)
  6. Use restic copy to copy all snapshots from the main repo to the secondary repo. As all packs files needed should already be in the repo, only the snapshots are created and thus copying should be fast.

I reckon there is no better/more direct way…