rustic-rs / rustic_core

rustic_core - library for fast, encrypted, deduplicated backups that powers rustic-rs
https://rustic.cli.rs/ecosystem/rustic-core/
Apache License 2.0
32 stars 13 forks source link

`forget`: Add option to automatically merge snapshots #17

Open enboig opened 2 years ago

enboig commented 2 years ago

When deleting snapshots, I would link to keep the latest version of a file that has been deleted. An example is:

aawsome commented 2 years ago

Thanks for proposing this issue!

I think I partly understood your intention, but I'm not perfectly sure if I did get all details. Can you clarify your request a bit?

Are you thinking of

at least in one snapshot?

And what do you think rustic should do to preserve the file:

aawsome commented 2 years ago

Ok, I think I might have understood what you mean (or at least I can imagine an algorithm which may suit your needs):

Is this what you are asking for?

enboig commented 2 years ago

Yes, it is.

I like the "no delete"; but I would tag it with a "dirty", "inconsistent", "frankenstein" tag

enboig commented 2 years ago

And the algorithm should be:

This way you would have always a "intersnapshot" containing the last version of every files, including the ones created and deleted between the full snapshots

aawsome commented 2 years ago

Marking this as duplicate because I think rustic-rs/rustic#43 will solve this.

enboig commented 2 years ago

Well... I would say they are related; but I was asking for an option when "forgetting" snapshots which automatically take care of merging snapshots which are being forgotten.

aawsome commented 2 years ago

Well... I would say they are related; but I was asking for an option when "forgetting" snapshots which automatically take care of merging snapshots which are being forgotten.

I was actually thinking about "merging" snapshots with an option to remove (a.k.a forget) the snapshots which are merged. So IMO your request can be satisfied with the new merge command.

That said, the filtering of the snapshots-to-be-merged can be a bit tricky, but here I have two proposals:

enboig commented 2 years ago

I like the idea of extending forget with something like --keep-files-last-version which merge snapshots to be forgotten and tag them someway so user (and rustic itself) identify them. But I would talk to restic developers first, keeping both tools as much similar as possible would be nice.

aawsome commented 1 year ago

@enboig The merge command has been implemented (see rustic-rs/rustic#411) and is available in the latest beta builds.

You can use rustic merge --delete <snap1> <snap2> <snap3>... to merge and remove a list of snapshots. Moreover, you can use rustic merge --delete --filter-* to merge and remove all snapshots which satisfy a filter.

I hope this fits your usecase, but don't heasitate to write if something is missing...

enboig commented 1 year ago

Thanks, I will take a look at it. Can an "already taken" snapshot be tagged with extra tags?

aawsome commented 1 year ago

Can an "already taken" snapshot be tagged with extra tags?

Sure. There is the rustic tag command to add/remove/set tags. Note that this changes the snapshot id.

enboig commented 1 year ago

When merging snapshots, time of new snapshot is set to now; could it be set to "newest date of merged snapshots"?

aawsome commented 1 year ago

Yes, you are right. This is a better fit for the timestamp - especially as for identical files, also the latest version is taken. I'll change this.

enboig commented 1 year ago

and when there are identical snapshots, there appear a (+2) next to it; could it appear a (M) next to a merged snapshot? or should I tag them manually?

enboig commented 1 year ago

And after some testing, the snapshot order in terminal isn't taken into account when merging; they are always merged keeping newest version of each file (which I think is the best option). Am I right?

aawsome commented 1 year ago

and when there are identical snapshots, there appear a (+2) next to it; could it appear a (M) next to a merged snapshot? or should I tag them manually?

Sorry, I didn't get what you are asking. Can you try to rewrite which behavior you are expecting? Note that the (+2) is only a output-format thing. You can always see all snapshots if you use the --all option or when you output the snapshots in json format.

aawsome commented 1 year ago

And after some testing, the snapshot order in terminal isn't taken into account when merging; they are always merged keeping newest version of each file (which I think is the best option). Am I right?

Right. I think the order of snapshots shouldn't play any role. Currently the newest version (i.e. latest modification timestamp) is taken if a file is contained in more than one snapshots. Please open an issue if you need other merging strategies!

enboig commented 1 year ago

Could it be any way of identify merged snapshots? What are "labels" used for? (I don't remember seeing them in restic)

aawsome commented 1 year ago

Could it be any way of identify merged snapshots? What are "labels" used for? (I don't remember seeing them in restic)

You can use a label and/or tags to identify them, e.g. rustic merge --label LABEL --tag TAG1,TAG2. restic doesn't support labels, which means that a snapshot with a label can be used in restic, but it is not displayed or can be used for anything.

Another possibility is to use a description (also not supported in restic) rustic merge --description "My description", but there is no way to e.g. filter for it and it is only shown by rustic snapshots --long or rustic snapshots --json.

BTW: rustic-rs/rustic#501 is merged and available in the latest beta build.

enboig commented 1 year ago

Returning to my initial idea... my objective is being able to rustic forget ... --keep-all-merged and go from

1

to

2

I know id of merged snapshot would change, the status of "merged snapshot" shouldn't be able to be modified by user. And id action
1 keep
2 forget
3 forget
4 keep
5 forget
6 keep
Should become id condition
1 normal
2' merged
4 normal
5' merged
6 normal

(status or condition of a snapshot (normal, merged, ...) should be set by rustic itself, not by user)

aawsome commented 1 year ago

Sorry for coming back lately to this topic. I know, that what you intend is not yet possible with the forget command, but maybe the -filter-fn option would work for you.

In your example, you could do something like

rustic merge --filter-fn '|sn| sn-time < "2023-03-17T15:58:30"' --delete --label Merged

To test out our --filter-fn funciotn, run it on the snapshots command and view the result...