Created
April 13, 2011 00:10
-
-
Save shigeyas/916720 to your computer and use it in GitHub Desktop.
Simple shell script to take daily ZFS snapshot and backup on different partition via bzip2
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
#!/bin/sh | |
# For FreeBSD 8.x. Place this file in /etc/periodic/daily and configure via periodic.conf | |
# | |
# If there is a global system configuration file, suck it in. | |
# | |
if [ -r /etc/defaults/periodic.conf ] | |
then | |
. /etc/defaults/periodic.conf | |
source_periodic_confs | |
fi | |
: ${daily_local_zfs_snapshot_tag=DAILY-} | |
: ${daily_local_zfs_snapshot_pool=rpool} | |
: ${daily_local_zfs_snapshot_backup_path=/bak/BACKUP/} | |
: ${daily_local_zfs_snapshot_backup_pre="mount /bak"} | |
: ${daily_local_zfs_snapshot_backup_post="umount /bak"} | |
BAKPATH=${daily_local_zfs_snapshot_backup_path} | |
POOL=${daily_local_zfs_snapshot_pool} | |
TAG=${daily_local_zfs_snapshot_tag} | |
SNAP=$TAG`date +%Y-%m%d-%H%M` | |
case "$daily_local_zfs_snapshot_enable" in | |
[Yy][Ee][Ss]) | |
echo | |
echo "Daily ZFS snapshot:" | |
zfs snapshot -r $POOL@$SNAP | |
echo Snapshot $POOL@$SNAP taken | |
LAST1=`zfs list -t snapshot -o name -d 1 |fgrep $TAG |sort |tail -1` | |
LAST2=`zfs list -t snapshot -o name -d 1 |fgrep $TAG |sort |tail -2|head -1` | |
LAST2AT=`echo $LAST2 | sed -e s/.*@//` | |
LAST1AT=`echo $LAST1 | sed -e s/.*@//` | |
BAKFILE="$BAKPATH$POOL@$LAST2AT+$LAST1AT.bz2" | |
${daily_local_zfs_snapshot_backup_pre} | |
if [ ! -e $BAKFILE ] | |
then | |
zfs send -R -i @$LAST2AT $LAST1 |bzip2 -9 > $BAKFILE | |
echo Backup file: $BAKFILE | |
fi | |
${daily_local_zfs_snapshot_backup_post} | |
rc=0 | |
;; | |
*) | |
rc=0 | |
;; | |
esac | |
exit $rc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment