Home software-development LXC snapshots scheduling and expiration

LXC snapshots scheduling and expiration

by Tomasz Jarosik

I run most of my containers with LXC. Just recently I discovered that there is a automatic way of making snapshots and expiring them. All you have to do is a few commands. You can apply these options per single container or per profile. In my case the profile is called “prod-nvme”:

lxc profile set prod-nvme snapshots.pattern 'snapshot-{{creation_date.Format("20060102")}}-%d'
lxc profile set prod-nvme snapshots.expiry "14d"
lxc config set prod-nvme-wordpress snapshots.schedule "0 2 * * SAT"

Snapshots schedule follows CRON format so it’s very easy to use. See https://crontab.guru/#0_2_*_*_SAT for explanation of above schedule. All newly created snapshots will follow snapshots.pattern and they will expire after 14 days. This doesn’t apply to patterns created before setting the schedule. And it will apply to all manual snapshots created after setting up the schedule.

$ lxc info prod-nvme-wordpress
Name: prod-nvme-wordpress
Created: 2018/06/23 16:33 UTC
Status: Running
Type: container
Profiles: default, prod-nvme
.............
Snapshots:
  prod-nvme-wordpress-30-04-2020 (taken at 2020/04/30 20:08 UTC) (stateless)
  backup-1.05.2020 (taken at 2020/05/01 20:28 UTC) (stateless)
  backup-23.05.2020 (taken at 2020/05/23 21:07 UTC) (stateless)
  snapshot-20200606-0 (taken at 2020/06/06 00:00 UTC) (expires at 2020/06/20 00:00 UTC) (stateless)

0 comment

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More