Public bug reported:

Idea/enhancement request.

I wrote a small initramfs script to snapshot the zpool when booting off
zfs in Ubuntu. As the pool is not actively used at that moment, it is in
the perfect consistent state to take snapshots. Perhaps this is
functionality more people are interested in?

To use it, you do 2 things:
- put the script in /etc/initramfs-tools/scripts/local-bottom and update the 
initrd (update-initramfs -ck all)
- add a boot parameter in the form of ZFSSNAP=xx in /etc/default/grub and run 
update-grub. xx has to be an integer

As I did not want to tamper with the initrd too much, it does not
require any additional tools in the initrd image. However it uses the
zfs-auto-snapshot syntax using "boot" as identifier instead of
hourly/daily/weekly/monthly/yearly.

As mentioned above you trigger the script when adding ZFSSNAP=xx as a
grub parameter, where xx is an integer. The script will keep the last xx
days that contain valid "boot" snapshots, and delete older ones. The
number of snapshots on a single day is irrelevant.

The script goes in /etc/initramfs-tools/scripts/local-bottom, so runs
right after the root zpool is imported. Snapshot queries are done only
on the top level of the pool ("-d 1") to avoid the script slowing down
the boot process too much although this means orphans are possible if
the cleaning operation is interrupted (system reset for example).

If this kind of functionality would be supported by the systemd import
script, other zpools on the system could be snapshotted at import time
as well. I considered importing my other zpools in the initramfs stage
temporarily just for snapshotting them, but then decided to keep it all
simple and refrain from that. Only a zpool that is defined on the kernel
command line for the rootfs (root=ZFS=zpool/rootfs) will be taken into
account.

So basically, if you add ZFSSNAP=4 to grub and put the script in the
initrd image, you will end up with snapshots in the form 'dataset@zfs-
auto-snap_boot-YYYY-MM-DD-HHMM' for MYPOOL and all recursive datasets on
MYPOOL that don't have com.sun:auto-snapshot set to false. You will find
these snapshots for every time you have rebooted your machine but only
the last 4 days (re)boots occured.

Disclaimer: I am not a developer so the script might not be a piece of
art. It does the job though.

** Affects: zfs-linux (Ubuntu)
     Importance: Undecided
         Status: New

** Attachment added: "script for /etc/initramfs-tools/scripts/local-bottom"
   
https://bugs.launchpad.net/bugs/1639500/+attachment/4773061/+files/zfs-boot-snap

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1639500

Title:
  Snapshot the system zpool from within the initramfs

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/zfs-linux/+bug/1639500/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to