digint / btrbk

Tool for creating snapshots and remote backups of btrfs subvolumes
https://digint.ch/btrbk/
GNU General Public License v3.0
1.72k stars 124 forks source link

Question: when btrbk runs multiple times per day, preserve latest of that day only + follow preserve options #394

Open zilexa opened 3 years ago

zilexa commented 3 years ago

btrbk runs nightly, but sometimes I manually run it during the day. When I do that, I do not want to have multiple snapshots & backups:

20210531
20210531_1
20210531_2

Per day, I only want to keep the latest. But I still want btrbk to follow my retention policies (for example preserve snapshots of the past 6 days, past 3 weeks, past 2 months). Just not keep more than 1 backup per day in the snapshots dir and on the targets, if btrbk runs >1 times on a day, only preserve the latest one of that day.

That would do the opposite: preserve the first of the day (2021053) instead of the last of the day (20210531_2).

This is what my config looks like. A few default settings are the same for my system backup but I wasn't sure if they would be inherited properly so I just added them in there as well.

# Generic settings
# ----------------
lockfile                            /var/lock/btrbk.lock
transaction_log                     /home/asterix/docker/HOST/logs/btrbk.log
#stream_buffer                       256m

# Default settings & retention policy
# --------------------------------------------------
snapshot_create        ondemand
snapshot_dir           .timeline
snapshot_preserve_min  latest
snapshot_preserve      6d 3w 2m
target_preserve_min    latest
target_preserve        20d 10w 12m
archive_preserve_min   latest
archive_preserve       20d 10w 18m

# SYSTEM Backup settings with custom settings & retention policy
# --------------------------------------------------------------
volume /mnt/system
group System
    snapshot_create        ondemand
    snapshot_dir           timeline
    snapshot_preserve_min  latest
    snapshot_preserve      6d 3w 2m
    target_preserve_min    latest
    target_preserve        14d 6w 3m
    target /mnt/disks/backup1/system
    target /mnt/disks/backup2/system
  subvolume @
  subvolume @home
  subvolume @docker

# USER Backup config with default retention policy
# ------------------------------------------------
volume /mnt/disks/data1
group Users
  subvolume Users
  target /mnt/disks/backup1/data1
  target /mnt/disks/backup2/data1
digint commented 3 years ago

I'm afraid this is not possible. It's probably worth considering such an option, but I fear that it would make things very complicated and confusing (I believe this was discussed in some issue already, can't find it right now).

The solution is pretty simple: make a snapshot at midnight (or whatever yout preserve_hour_of_day config is).

I am a bit afraid to use snapshot_preserve_min 1d, I don't want btrbk to destroy all preserved snapshots and backups, only the older ones from today.

If you change snapshot_preserve_min from "latest" to "1d", it won't destroy more snapshots. In the contrary, it would keep all the backups from one day back, in addition to the snapshot_preserve settings.

I am also very afraid to us snapshot_preserve_min no, because the documentation states

You can't set snapshot_preserve_min to "no". The latest snapshot always needs to be preserved.

... and sorry for the late reply, I'm very busy these days...

camoz commented 2 years ago

(I believe this was discussed in some issue already, can't find it right now)

Also discussed in https://github.com/digint/btrbk/issues/413