Automatische Snapshots einrichten
Auf FreeBSD gibt es mehrere Wege, ZFS-Snapshots zu automatisieren. Ein bewährtes Tool ist zfs-auto-snapshot aus den Ports (sysutils/zfstools). Es orientiert sich an der Snapshot-Automatisierung von Solaris/OpenSolaris und kann auch konsistente Snapshots einer MySQL- oder PostgreSQL-Datenbank erstellen.
Hinweis: Seit FreeBSD 13 gibt es mit periodic(8) und dem ZFS-Periodic-Script eine eingebaute Alternative, die ohne zusätzliche Pakete auskommt. Für ältere Systeme oder mehr Kontrolle über die Retention bleibt zfstools eine gute Wahl.
Installation:
pkg install zfstools
Danach die Cronjobs in /etc/crontab eintragen:
# ZFS snapshots 15,30,45 * * * * root /usr/local/sbin/zfs-auto-snapshot frequent 4 0 * * * * root /usr/local/sbin/zfs-auto-snapshot hourly 24 7 0 * * * root /usr/local/sbin/zfs-auto-snapshot daily 7 14 0 * * 7 root /usr/local/sbin/zfs-auto-snapshot weekly 4 28 0 1 * * root /usr/local/sbin/zfs-auto-snapshot monthly 12
Falls zfs im Cronjob nicht gefunden wird, die PATH-Variable in der Crontab erweitern:
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
Jetzt noch die Snapshots für das gewünschte Dataset aktivieren:
zfs set com.sun:auto-snapshot=true zroot/usr/home
Retention-Schema
Mit der Crontab oben werden folgende Snapshots vorgehalten:
- Alle 15 Minuten — 4 Snapshots vorgehalten
- Stündlich — 24 Snapshots vorgehalten
- Täglich — 7 Snapshots vorgehalten
- Wöchentlich — 4 Snapshots vorgehalten
- Monatlich — 12 Snapshots vorgehalten
Snapshots prüfen
zfs list -r -H -t snapshot zroot/usr/home zroot/usr/home@zfs-auto-snap_hourly-2016-05-19-11h00 21,5M - 82,5G - zroot/usr/home@zfs-auto-snap_frequent-2016-05-19-11h30 14,6M - 82,6G - zroot/usr/home@zfs-auto-snap_frequent-2016-05-19-11h45 13,3M - 82,6G - zroot/usr/home@zfs-auto-snap_hourly-2016-05-19-12h00 14,0M - 82,7G -
Datenbank-Snapshots
Für konsistente Datenbank-Snapshots muss das Property auf dem Datenbank-Dataset speziell gesetzt werden — zfs-auto-snapshot friert die Datenbank dann vor dem Snapshot kurz ein:
# PostgreSQL zfs set com.sun:auto-snapshot=postgresql zroot/data/postgres # MySQL/MariaDB zfs set com.sun:auto-snapshot=mysql zroot/data/mysql
Wichtig: Snapshots auf demselben System sind kein Backup-Ersatz. Geht die Platte kaputt, sind die Snapshots mit weg. Für eine echte Sicherung die Snapshots per zfs send/recv auf ein zweites System replizieren.
Mehr zu ZFS: ZFS Compression und Deduplication. Details zu allen Snapshot-Optionen in der OpenZFS-Dokumentation. Fragen? Einfach melden.
Schreibe einen Kommentar