Now that I have ZFS up and running I would like to implement an automated snapshot mechanism. I have looked at zfs-snapshot-mgmt, but for my purposes I believe there is a simpler solution based on this sun.com blog. Being a ZFS neophyte, I thought I'd get the opinions of some ZFS experts before proceeding.
My solution would make use of ZFS's ability to set user-defined parameters. Users would add a parameter "autosnap:<label>"=<count> to filesystems for which they want auto-snapshots. <label> is a user defined name and <count> is the number of snapshots with that label to rotate through. This would create automatic snapshots named <label>.0, <label>.1, etc. Every time a new snapshot is created its label is incremented and any snapshots with labels numbered <count> or higher are destroyed. The newest snapshot is always <label>.0, and the oldest snapshot would be <label>.<count-1>.
I would write a single script "zfs-autosnap.sh <label> <filesystem>|all" which would rotate the <label> snapshots for each <filesystem>. Filesystems that do not have an autosnap:<label> are ignored. The special filesystem "all" would represent all filesystems.
Users could then add some crontab entries that would regularly run zfs-autosnap <label> on a regular basis.
EXAMPLE:
The following example would cause 24 hourly snapshots to be kept for filesystem "zroot/home":
The following crontab entries would rotate the "hourly" snapshots every hour, "daily" every day, etc.
Note that by default, any child filesystems would inherit the same autosnap configuration as their parents. Snapshot filesystems, which would also inherit the parameters from their parents, would be ignored.
Seems simple to implement, simple to administer. Seems to be in keeping with the intent of the zfs features used. What do the ZFS experts out there think?
My solution would make use of ZFS's ability to set user-defined parameters. Users would add a parameter "autosnap:<label>"=<count> to filesystems for which they want auto-snapshots. <label> is a user defined name and <count> is the number of snapshots with that label to rotate through. This would create automatic snapshots named <label>.0, <label>.1, etc. Every time a new snapshot is created its label is incremented and any snapshots with labels numbered <count> or higher are destroyed. The newest snapshot is always <label>.0, and the oldest snapshot would be <label>.<count-1>.
I would write a single script "zfs-autosnap.sh <label> <filesystem>|all" which would rotate the <label> snapshots for each <filesystem>. Filesystems that do not have an autosnap:<label> are ignored. The special filesystem "all" would represent all filesystems.
Users could then add some crontab entries that would regularly run zfs-autosnap <label> on a regular basis.
EXAMPLE:
The following example would cause 24 hourly snapshots to be kept for filesystem "zroot/home":
Code:
zfs set autosnap:hourly=24 zroot/home
The following crontab entries would rotate the "hourly" snapshots every hour, "daily" every day, etc.
Code:
0 * * * * root /root/bin/zfs-autosnap.sh hourly all
0 0 * * * root /root/bin/zfs-autosnap.sh daily all
0 0 * * 0 root /root/bin/zfs-autosnap.sh weekly all
0 0 1 * * root /root/bin/zfs-autosnap.sh monthly all
Note that by default, any child filesystems would inherit the same autosnap configuration as their parents. Snapshot filesystems, which would also inherit the parameters from their parents, would be ignored.
Seems simple to implement, simple to administer. Seems to be in keeping with the intent of the zfs features used. What do the ZFS experts out there think?