Renamed a host, what now?

This is a simple scenario, been bit by it several times in the past, but this time I’d like to hear what others are doing, maybe there’s a better solution than good old hammer approach which I used previously. :slight_smile:

So, I have this very important server in restic backup schedule, together with year or so of history (about 30 snapshots). For various important reasons, the server name had to be changed. Now, looking at my nightly restic workflow, I do unlock (just in case), backup, forget --prune with my preferred retention settings. And all is well, except, forget is now working only on snapshots created with new hostname! It seems to completely leave alone old snapshots, so they’re not getting pruned. I find this quite unconvenient.

So, I could fake an old hostname when doing backup, but no, I find that ugly, confusing, and when backups are the topic, no confusion is allowed IMHO, so I’m not going there…

I could start a new repo, this is what I usually did before, then delete the old one after some time, but this time I’d really like to keep what is there, for the whole year, together with new stuff, in the same repo, but also keep my retention setting. From what I understand, this repo will now tend to grow to double size (60 snapshots soon), and that is also not good (if I left everything as it is and don’t care).

The only other thing I see I could do is to manually manage, forget snapshots by snapshot that I deem not needed as time passes by. Based on my retention setting, I’d now delete one specific old snapshot for the next 14 days, then proceed to delete one weekly for the next 8 weeks, and finally delete one monthly snapshots every month. And eventually I’d have to keep that one yearly I have. :slight_smile: No, this seems like an awful lot of micro-managing error-prone manual work. Refuse to to that either! :slight_smile:

When you rename a host, what are you doing? Is there some magic combination of --hostname or similar switches that solves the above nuissance?

Thanks for any answer!

There’s another option: don’t use the host name recorded in the snapshots when grouping the snapshots before applying the retention policy with --group-by paths. By default, restic splits the list of snapshots into several lists based on the paths, the hostname and the paths (--group-by host,paths).

If you only have snapshots from a single host (which was renamed) in the repo that’s straight-forward. It may be more problematic when you have other hosts with the same paths in the same repo, restic will then apply the retention policy as if all snapshots were for the same host. You could work around that by applying a tag (even to old snapshots), e.g. foobar, then call forget twice, once with --keep-tags foobar for the other hosts and once with --tag foobar --group-by paths.

Please make plenty use of --dry-run when experimenting with different settings for forget!

Did I explain that well?

4 Likes

Dear fd0,

not only you explained it well, it’s obviously that perfect solution I was looking for. :+1:

I’m really happy I went public with this issue, 'cause the solution is already there, and only half an hour away. :slight_smile:

Yeah, --dry-run run (together with magic --group-by incatation) reveals that exactly those snapshots I’d like to get pruned are on the list. Thanks for that specific hint, too! Restic, being so maintenance free all these years, I’ve even managed to forget about --dry-run. :slight_smile:

IMHO, this advice deserves explicit place in the manual. I did consult manual before asking for help here, but somehow completely missed even the existance of --group-by parameter (mostly concentrating on --hostname). This might be the common case, changing the hostname, but of course, up to you to decide if it’s important enough to be mentioned in the official documentation and more visible place.

Nevertheless, thanks for a really great help as always, and I feel it’s that time of the year where I just must buy you a beer for such a great product and support. :smiley:

2 Likes

I had some similar issue in the past. I reinstalled my system on my laptop and set a new username for the new installation. The hostname was the same but the path was different. So, what I did was to use the same tag for all snapshots for this host and used forget --group-by tags and worked just fine. It is also easier because the only thing you can actually change in snapshots is tags and if the old snapshots have another tag and you want to include those snapshots, you just have to change the tag. I mean, I don’t know if I’m totally right but at least for me it worked. I use one specific tag for each host, so other hosts in the repo were not affected. If you want to make sure that this work for this specific tag used just add the --tag flag: e.g.: forget --group-by tags --tag foobar --dry-run so it supposed to forget just for foobar tag, AFAIK.

1 Like