Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is restic support use --keep-last and --keep-daily together #1562

Closed
gung-rgb opened this issue Jan 17, 2018 · 7 comments
Closed

is restic support use --keep-last and --keep-daily together #1562

gung-rgb opened this issue Jan 17, 2018 · 7 comments
Labels
type: question/problem usage questions or problem reports

Comments

@gung-rgb
Copy link

is restic support use --keep-last and --keep-daily together? and or or ? for example:

restic forget --keep-daily  10  --keep-last 10

the kept snapshots are that satisfy last 10 and in 10 days ? or the kept snapshots are satisfy only one condition?

@rawtaz
Copy link
Contributor

rawtaz commented Jan 19, 2018

@gongmingbin There's a dry run option to the forget command:

-n, --dry-run do not delete anything, just print what would be done

You can use it to run your command and see what would be done, without having it done.

Run restic help and e.g. restic help forget to see more options.

@fd0
Copy link
Member

fd0 commented Jan 19, 2018

I've built an example for you, let's say I have an hourly backup for a directory for the last couple of days:

$ restic snapshots
[...]
ID        Date                 Host        Tags  
----------------------------------------------------------------------
502d4a5d  2018-01-17 00:01:02  mopped      
3f810aca  2018-01-17 01:01:02  mopped      
a5828f0c  2018-01-17 02:01:02  mopped      
d3646597  2018-01-17 03:01:02  mopped      
56302763  2018-01-17 04:01:02  mopped      
213558ab  2018-01-17 05:01:02  mopped      
194c98f8  2018-01-17 06:01:02  mopped      
[...]
44c7c35e  2018-01-19 05:01:02  mopped      
bf473f50  2018-01-19 06:01:02  mopped      
c446308a  2018-01-19 07:01:02  mopped      
1af5ec53  2018-01-19 08:01:02  mopped      
41f66504  2018-01-19 09:01:02  mopped      
890f46c8  2018-01-19 10:01:02  mopped      
730b62f6  2018-01-19 11:01:02  mopped      
bb787c55  2018-01-19 12:01:02  mopped      
59018a09  2018-01-19 13:01:02  mopped      
----------------------------------------------------------------------
62 snapshots

When you run restic with --keep-last 10 and --keep-daily 2, this is the result:

$ restic forget --dry-run --keep-last 10 --keep-daily 2
[...]
keep 11 snapshots:
ID        Date                 Host        Tags        Directory
----------------------------------------------------------------------
573c701b  2018-01-18 23:01:02  mopped                  /home/fd0/work
19f1ad8d  2018-01-19 04:01:02  mopped                  /home/fd0/work
44c7c35e  2018-01-19 05:01:02  mopped                  /home/fd0/work
bf473f50  2018-01-19 06:01:02  mopped                  /home/fd0/work
c446308a  2018-01-19 07:01:02  mopped                  /home/fd0/work
1af5ec53  2018-01-19 08:01:02  mopped                  /home/fd0/work
41f66504  2018-01-19 09:01:02  mopped                  /home/fd0/work
890f46c8  2018-01-19 10:01:02  mopped                  /home/fd0/work
730b62f6  2018-01-19 11:01:02  mopped                  /home/fd0/work
bb787c55  2018-01-19 12:01:02  mopped                  /home/fd0/work
59018a09  2018-01-19 13:01:02  mopped                  /home/fd0/work
----------------------------------------------------------------------
[...]

I find it confusing to talk about "and" and "or" here. restic follows the policy you give it:

  • --keep-last 10 means the newest ten snapshots will be kept
  • --keep-daily 2 means the latest snapshot for the last two days (for which a snapshot exists) will be kept

restic then goes through all the snapshots available and marks which ones will be kept. The snapshot 59018a09 for example will be kept because it is within the last ten and because it is the latest snapshot of a day within the last two days.

So, in a sense you could say that the conditions for keeping a snapshot are combined via or.

I think this answers your question, so I'm closing this issue. If you have follow-up questions (or I wasn't clear enough), please add a comment.

For these types of questions the forum is a much better place, we're using the GitHub issue tracker for tracking bugs and features.

@fd0 fd0 closed this as completed Jan 19, 2018
@fd0 fd0 added the type: question/problem usage questions or problem reports label Jan 19, 2018
@gung-rgb
Copy link
Author

Thank you! @fd0 But I found --keep--xx not working.
Here is my local snapshots
image
when i run

restic forget --dry-run  --keep-yearly 10

result is:
image
is this a bug or something wrong with me?
my system is macOS 10.13 Darwin 17.0.0.

@dimejo
Copy link
Contributor

dimejo commented Jan 20, 2018

You told restic to keep 1 snapshot per year for 10 years. Since you only have snapshots from 2018 and 306e3a4a was the last snapshot from 2018 restic is keeping only this one.

How many snapshots per period do want to keep? Maybe we can help you with the policy.

@gung-rgb
Copy link
Author

@dimejo , sorry,Maybe I misunderstood. is the --keep-yearly 10 mean than restic will kept all then snapshots than is from last 10 ago to now? for my example, the three snapshots was in the last 10 years, way not all of them will be kept?
I just want to kept The past n year snapshots.

@fd0
Copy link
Member

fd0 commented Jan 20, 2018

@gongmingbin I think restic does exactly what you asked it to do. Did you find the section in the manual that covers removing snapshots according to a policy? https://restic.readthedocs.io/en/latest/060_forget.html#removing-snapshots-according-to-a-policy

Running restic forget --keep-yearly 10 instructs restic to keep one snapshot for the last ten years for which snapshots were made. So if you have 10 snapshots from 2018, 8 snapshots from 2017 and 3 snapshots from 2015, restic would remove all except the last from each year, so you'll end up with just three snapshots.

Is there anything unclear?

@gung-rgb
Copy link
Author

Thank you very match!! I misunderstand for my bad English and reading doc carelessly! Thank you for your patient answers again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question/problem usage questions or problem reports
Projects
None yet
Development

No branches or pull requests

4 participants