review of edited periodic zfs-snapshot

Hello all.

I used to do the snapshots daily and hourly with the port sysutils/zfs-periodic. It works great, however I also would like to send them. Now are my shell scripting skills limited or almost not existing.

This is what I have done:

I edited the periodic script /usr/local/etc/periodic/hourly/000.zfs-snapshot and for the daily part I edited the daily script and replaced hourly with daily.

Code:
case "$hourly_send_zfs_snapshot_enable" in
    [Yy][Ee][Ss])
        . /usr/local/bin/zfs-snapshot
        send_snapshots "$pool" 'hourly'
        ;;
    *)
        ;;
esac

In the main script /usr/local/bin/zfs-snapshot I did add the following.

Code:
send_snapshots()
{
    pool=$1
    type=$2

   case "$type" in
        hourly)
        now=`date +"$type-%Y-%m-%d-%H"`
        last=`date -v -1H +"$type-%Y-%m-%d-%H"`
        ;;
        daily)
        now=`date +"$type-%Y-%m-%d"`
        last=`date -v -1d +"$type-%Y-%m-%d"`
        ;;
        weekly)
        now=`date +"$type-%Y-%U"`
        last=`date -v -1w +"$type-%Y-%U"`
       ;;
        monthly)
        now=`date +"$type-%Y-%m"`
        last=`date -v -1m +"$type-%Y-%m"`
        ;;
        *)
        echo "unknown snapshot type: $type"
        exit 1
    esac

    snapshot=$pool@$now
    snapshot_last=$pool@$last

    if  zfs list -H -o name -t snapshot | sort | grep $snapshot_last$  > /dev/null; then
             echo "$snapshot_last exists send the backup"
             echo " Sending incremental $snapshot_last $snapshot to $host"
             zfs send -R -i $snapshot_last $snapshot | ssh root@192.168.50.200 zfs receive -Fduv zpool_bck"
             echo "backup complete destroy old snapshot"
             delete_snapshot $snapshot_last
    else
        echo "old snapshot $snapshot_last is not there"
                fi
#   fi
}

My concerns are that I missed something and that things go wrong. Especially the delete part!

Is the following correct? I used the delete_snapshot function already in the script.
Code:
             echo "backup complete destroy old snapshot"
             delete_snapshot $snapshot_last

That function is here:
Code:
delete_snapshot()
{
    snapshot=$1
    echo "  destroying old snapshot, $snapshot"
    zfs destroy -r $snapshot
}
Is it right to think that my $snapshot_last is becoming $snapshot in this function? I think it is but I am not sure.

Thanks for your time.
 
Back
Top