Last active
March 18, 2023 16:15
-
-
Save mariancerny/cbe7751c39910fb4abd0 to your computer and use it in GitHub Desktop.
Scripts to perform ZFS hourly, daily and monthly backups using ZFS snapshot feature.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ZFS Backups | |
3 0 * * * root sh /opt/sbin/zfs-backup.sh | |
2 1-23 * * * root sh /opt/sbin/zfs-backup-hourly.sh | |
33 10 9 * * root sh /opt/sbin/zfs-backup-monthly.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -e | |
two_days_ago=$( date -v-2d +%A ) | |
pools=`zpool list -H -o name` | |
datasets=`zfs list -d 1 -H -o name | grep /` | |
for pool in $pools | |
do | |
# Maly HACK ako sa vyhnut hlaske, ze snaphost s danym menom neexistuje. | |
# Vytvorime si snaphost priamo na hlavny dataset poolu, ktory vzapeti | |
# hned zmazeme. | |
zfs snapshot $pool@$two_days_ago | |
zfs destroy -r $pool@$two_days_ago | |
done | |
for dataset in $datasets | |
do | |
zfs rename -r $dataset@yesterday $two_days_ago || echo "Failed to zfs rename $dataset@yesterday" | |
zfs rename -r $dataset@today yesterday || echo "Failed to zfs rename $dataset@today" | |
zfs snapshot -r $dataset@today | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -e | |
hour=$( date +%H:00 ) | |
pools=`zpool list -H -o name` | |
# BACKUP nesnapshotujeme kazdu hodinu, iba kazdy den. | |
datasets=`zfs list -d 1 -H -o name | grep / | grep -v BACKUP` | |
for pool in $pools | |
do | |
# Maly HACK ako sa vyhnut hlaske, ze snaphost s danym menom neexistuje. | |
# Vytvorime si snaphost priamo na hlavny dataset poolu, ktory vzapeti | |
# hned zmazeme. | |
zfs snapshot $pool@$hour | |
zfs destroy -r $pool@$hour | |
done | |
for dataset in $datasets | |
do | |
zfs snapshot -r $dataset@$hour | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -e | |
# Tento skript je potreba pustat 9. v mesiaci a premenuje poslednu zalohu (pred 8. dnami) na aktualny mesiac. | |
# Vynechava BACKUP a /tmp. | |
month=$( date +%B ) | |
eight_days_ago=$( date -v-8d +%A ) | |
pools=`zpool list -H -o name` | |
# BACKUP a /tmp nesnapshotujeme kazdy mesiac. | |
datasets=`zfs list -H -o name | grep / | egrep -v 'BACKUP|/tmp' ` | |
for pool in $pools | |
do | |
# Maly HACK ako sa vyhnut hlaske, ze snaphost s danym menom neexistuje. | |
# Vytvorime si snaphost priamo na hlavny dataset poolu, ktory vzapeti | |
# hned zmazeme. | |
zfs snapshot $pool@$month | |
zfs destroy -r $pool@$month | |
done | |
for dataset in $datasets | |
do | |
zfs rename $dataset@$eight_days_ago $dataset@$month || echo "Failed to zfs rename $dataset@$eight_days_ago $dataset@$month" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This set of scripts provides: