Created
February 12, 2013 18:49
-
-
Save alksl/4772223 to your computer and use it in GitHub Desktop.
ZFS backup
This file contains hidden or 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
#!/bin/sh | |
BACKUP_ROOT=/mnt/backup | |
now=$(date +%s) | |
readable=$(date -d $now +%F) | |
backup_name="${readable}-${now}" | |
mount /mnt/backup | |
zfs snapshot -r zroot@${backup_name} | |
zfs send -R zroot@${backup_name} | gzip | dd of=${BACKUP_ROOT}/${backup_name} bs=1M | |
# Backup completed clean up old ones | |
backups=$(ls "${BACKUP_ROOT}") | |
for backup in $backups | |
do | |
timestamp=$(echo "${backup}" | cut -d"-" -f4) | |
if [ "${timestamp}" -lt "${now}" ] | |
then | |
echo "Removing ${backup}" | |
rm "${BACKUP_ROOT}/${backup}" | |
zfs destroy -r zroot@${backup} | |
fi | |
done | |
umount /mnt/backup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment