Automatisch ZFS Snapshots erstellen
Verwendet man das ZFS Dateisystem, können mit zfs-snapshot-mgmt regelmässig automatisch ZFS Snapshots erstellt werden. Im FreeBSD Portbaum findet man zfs-snapdhot-mgmt unter sysutils/zfs-snapshot-mgmt:
# cd /usr/ports/sysutils/zfs-snapshot-mgmt && make install clean
Nun kann unter /usr/local/etc/zfs-snapshot-mgmt.conf eine Konfiguration erstellt werden, in der festgelegt wird, wann Snapshots erstellt werden sollen, wie lange die verschiedenen Snapshots erhalten bleiben sollen und wann sie dementsprechend automatisch wieder gelöscht werden:
# Automatic ZFS snapshot management configuration file # # This is a YAML file (see http://www.yaml.org) # Use exactly 2 spaces for each indentation level # snapshot_prefix: auto- filesystems: tank/home: # Create snapshots every 10 minutes, starting at midnight creation_rule: at_multiple: 10 offset: 0 # Keep all snapshots for the first 90 minutes, # then only those that were created at 30 minute intervals for 12 hours # (after snapshot creation), # then only those that were created at 3 hour intervals, counting at 2:00 # (i.e. 2:00, 5:00, 8:00, 11:00, 14:00, 17:00, 20:00, 23:00) # for 7 days preservation_rules: - { for_minutes: 90, at_multiple: 0, offset: 0 } - { for_minutes: 720, at_multiple: 30, offset: 0 } - { for_minutes: 10080, at_multiple: 180, offset: 120 } tank/ports: # Create snapshots every 24 hours, starting at 20:00. creation_rule: at_multiple: 1440 offset: 1200 # Keep daily snapshots created at 20:00 (in this case all). preservation_rules: - { for_minutes: 5760, at_multiple: 1440, offset: 1200 }
Ist die Konfiguration erstellt, kann der benötigte crontab-Eintrag gemacht werden, so dass die Snapshots automatisch erstellt und gelöscht werden:
# echo "*/5 * * * * root /usr/local/bin/zfs-snapshot-mgmt" >> /etc/crontab
Die aktuell vorhandenen Snapshots können mit zfs list angezeigt werden:
# zfs list NAME USED AVAIL REFER MOUNTPOINT tank 3,06G 11,6G 18K /tank tank/home 982M 11,6G 770M /usr/home tank/home@auto-2008-09-06_10.00 65,3M - 682M - tank/home@auto-2008-09-07_11.00 54,4M - 682M - tank/home@auto-2008-09-07_16.00 0 - 682M - tank/home@auto-2008-09-07_21.00 0 - 682M - tank/home@auto-2008-09-08_22.00 0 - 682M - tank/home@auto-2008-09-09_13.00 0 - 682M - tank/home@auto-2008-09-09_18.00 0 - 682M - tank/home@auto-2008-09-09_23.00 0 - 682M - tank/home@auto-2008-09-10_09.00 0 - 682M - tank/home@auto-2008-09-10_14.00 0 - 682M - tank/home@auto-2008-09-11_00.00 0 - 682M - tank/home@auto-2008-09-11_10.00 0 - 682M - tank/home@auto-2008-09-11_15.00 36K - 682M - tank/home@auto-2008-09-12_09.00 286K - 746M - tank/home@auto-2008-09-12_09.30 247K - 746M - tank/home@auto-2008-09-12_10.00 49K - 763M - tank/home@auto-2008-09-12_10.30 0 - 763M - tank/home@auto-2008-09-12_11.00 0 - 763M - tank/home@auto-2008-09-12_11.30 0 - 763M - tank/home@auto-2008-09-12_12.00 0 - 763M - tank/home@auto-2008-09-12_12.30 0 - 763M - tank/home@auto-2008-09-12_13.00 0 - 763M - tank/home@auto-2008-09-12_13.30 29K - 770M - tank/home@auto-2008-09-12_14.00 0 - 770M - tank/home@auto-2008-09-12_14.30 0 - 770M - tank/home@auto-2008-09-12_14.50 0 - 770M - tank/home@auto-2008-09-12_15.00 0 - 770M - tank/home@auto-2008-09-12_15.10 0 - 770M - tank/home@auto-2008-09-12_15.20 0 - 770M - tank/home@auto-2008-09-12_15.30 0 - 770M - tank/home@auto-2008-09-12_15.40 0 - 770M - tank/home@auto-2008-09-12_15.50 0 - 770M - tank/home@auto-2008-09-12_16.00 0 - 770M - tank/home@auto-2008-09-12_16.10 0 - 770M - tank/obj 1,62G 11,6G 1,62G /usr/obj tank/ports 800M 11,6G 800M /usr/ports tank/ports@auto-2008-09-09_10.00 36K - 493M - tank/src 493M 11,6G 493M /usr/src
Mehr Informationen findet man in der Manpage zfs-snapshot-mgmt(8). Eine Einführung in das Arbeiten mit ZFS und ZFS Snapshots findet man hier: http://www.chruetertee.ch/blog/archive/2007/05/26/zfs-auf-freebsd.html