Snapper's dnf snapshot cleanups

,

Hi everyone!

I recently set up Snapper for my system (following this guide that was linked in a previous topic I opened about it) for Fedora 34 and it’s doing its job, but I am currently having a hard time with the options. It looks like the scheduler does not clean up the timeline according to my settings, as I currently have 83 snapshots on my system:

$ pwd
/etc/snapper/configs

$ sudo cat root

# subvolume to snapshot
SUBVOLUME="/"

# filesystem type
FSTYPE="btrfs"


# btrfs qgroup for space aware cleanup algorithms
QGROUP=""


# fraction of the filesystems space the snapshots may use
SPACE_LIMIT="0.5"

# fraction of the filesystems space that should be free
FREE_LIMIT="0.2"


# users and groups allowed to work with config
ALLOW_USERS=""
ALLOW_GROUPS=""

# sync users and groups from ALLOW_USERS and ALLOW_GROUPS to .snapshots
# directory
SYNC_ACL="no"


# start comparing pre- and post-snapshot in background after creating
# post-snapshot
BACKGROUND_COMPARISON="yes"


# run daily number cleanup
NUMBER_CLEANUP="yes"

# limit for number cleanup
NUMBER_MIN_AGE="1800"
NUMBER_LIMIT="50"
NUMBER_LIMIT_IMPORTANT="10"


# create hourly snapshots
TIMELINE_CREATE="yes"

# cleanup hourly snapshots after some time
TIMELINE_CLEANUP="yes"

# limits for timeline cleanup
TIMELINE_MIN_AGE="1800"
TIMELINE_LIMIT_HOURLY="3"
TIMELINE_LIMIT_DAILY="5"
TIMELINE_LIMIT_WEEKLY="0"
TIMELINE_LIMIT_MONTHLY="0"
TIMELINE_LIMIT_YEARLY="0"


# cleanup empty pre-post-pairs
EMPTY_PRE_POST_CLEANUP="yes"

# limits for empty pre-post-pair cleanup
EMPTY_PRE_POST_MIN_AGE="1800"

Would you be able to point me towards what I am failing to set up?

Additionally (I would normally avoid 2 questions in one post, but they are related), I can’t get to work the bit that Chris Murphy’s mentioned in his post without messing up /etc/fstab/, so if you could please help with that it would be great.

2 Likes

I’ve noticed there’s snapper-cleanup.timer which is disabled by default. Enabling this service:

sudo systemctl enable --now snapper-cleanup.timer

Should result in something like:

$ systemctl status snapper-cleanup.timer
● snapper-cleanup.timer - Daily Cleanup of Snapper Snapshots
     Loaded: loaded (/usr/lib/systemd/system/snapper-cleanup.timer; enabled; vendor preset: disabled)
     Active: active (waiting) since Mon 2021-06-21 22:22:38 CEST; 11h ago
    Trigger: Tue 2021-06-22 22:22:38 CEST; 12h left
   Triggers: ● snapper-cleanup.service
       Docs: man:snapper(8)
             man:snapper-configs(5)

Jun 21 22:22:38 main systemd[1]: Started Daily Cleanup of Snapper Snapshots.

So it will trigger daily snapshot cleanup (trigger of snapper-cleanup.service)

3 Likes

According to the openSUSE Snapper Tutorial the cron scheduler is the default and the systemd service is an alternative. If the timeline snapshots are being made then presumably cron is running correctly?

@fbackstab have you checked in /var/log/snapper.log to see if there are any relevant error messages?

1 Like

Thank you both for your replies.

I activated the service, it does trigger the clean up but it does not clean it up (I am still at 83 snapshots atm)

It does not look like, here’s the log.

The only thing that looks like it is 2021-06-11 13:35:13 WAR libsnapper(38461) Client.cc(dispatch):1860 - CAUGHT: quota rescan or sync failed

Edit: apparently now it works (just took a while), so I suppose it’s been the systemd service. Now I have both activated, what shall I do? Deactivate the cronie scheduler and retain systemd or vice versa (i.e. fix the cronie one and use systemd as a temporary solution)?

Glad you got it working!

I’ve just checked both snapper and snapper-libs package contents:

$ rpm -ql snapper | grep -i cron
$ rpm -ql snapper-libs | grep -i cron

And as you can see, I see no crontab file which would trigger it regularly. Is that something you created on your own?

If you’re following OpenSUSE documentation, beware that some things may be different, after all, although the program is the same, build and package might not be.

3 Likes

The problem here is that things like how job scheduling works is usually a distro specific implementation detail. On Suse, using the cron might be the default but on Fedora, maybe not.

Can we see what your cron job looks like?

2 Likes

I do not think I created one, is there any way I can check just to be sure?

$ sudo systemctl status crond.service 
crond.service - Command Scheduler
     Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor pre>
     Active: active (running) since Wed 2021-06-23 12:54:49 BST; 31min ago
   Main PID: 1907 (crond)
      Tasks: 1 (limit: 38022)
     Memory: 1.3M
        CPU: 82ms
     CGroup: /system.slice/crond.service
             └─1907 /usr/sbin/crond -n

Jun 23 12:54:49 fedora crond[1907]: (CRON) INFO (RANDOM_DELAY will be scaled wi>
Jun 23 12:54:49 fedora crond[1907]: (CRON) INFO (running with inotify support)
Jun 23 13:01:01 fedora CROND[5099]: (root) CMD (run-parts /etc/cron.hourly)
Jun 23 13:01:01 fedora anacron[5112]: Anacron started on 2021-06-23
Jun 23 13:01:01 fedora anacron[5112]: Will run job `cron.daily' in 7 min.
Jun 23 13:01:01 fedora anacron[5112]: Jobs will be executed sequentially
Jun 23 13:01:01 fedora CROND[5098]: (root) CMDEND (run-parts /etc/cron.hourly)
Jun 23 13:08:01 fedora anacron[5112]: Job `cron.daily' started
Jun 23 13:08:01 fedora anacron[5112]: Job `cron.daily' terminated
Jun 23 13:08:01 fedora anacron[5112]: Normal exit (1 job run)

That is the status of the cron service. The cron job is the thing that runs snapper.

It could be in a variety of places:

  • one of the files in /etc/cron.d
  • In root’s crontab sudo crontab -l
  • In your crontab(not likely) crontab -l

If you don’t find a cron job, maybe snapper isn’t running from the cron at all.

Whoops, sorry.

I have just the file 0hourly in /etc/cron.d:

$ cat 0hourly 
# Run the hourly jobs
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
01 * * * * root run-parts /etc/cron.hourly

The other commands report just no crontab, so I suppose it isn’t running from the cron?

1 Like

Probably not.

What does this command show:

 systemctl list-timers --all | grep snapper 
1 Like
$  systemctl list-timers --all | grep snapper 
Thu 2021-06-24 13:05:21 BST 20h left      Wed 2021-06-23 13:05:21 BST 3h 7min ago  snapper-cleanup.timer        snapper-cleanup.service

Which should be the one I activated before through @masteroman 's suggestion

OK, how about this one:

systemctl status snapperd

If that is running, that is what is taking your snapshots.

$ systemctl status snapperd
○ snapperd.service - DBus interface for snapper
     Loaded: loaded (/usr/lib/systemd/system/snapperd.service; static)
     Active: inactive (dead)
       Docs: man:snapperd(8)

Jun 23 13:05:21 fedora systemd[1]: Starting DBus interface for snapper...
Jun 23 13:05:21 fedora systemd[1]: Started DBus interface for snapper.
Jun 23 13:06:22 fedora systemd[1]: snapperd.service: Deactivated successfully.

Edit: giving a second look to my snapshots, I do not have the hourly snapshots I should have with TIMELINE_CREATE="yes" either, it’s only pre/post installation. Might that be related?

For that I think you need to enable snapper-timeline.timer.

sudo systemctl enable --now snapper-timeline.timer