#! /bin/ksh # * CDDL HEADER START # * # * The contents of this file are subject to the terms of the # * Common Development and Distribution License (the "License"). # * You may not use this file except in compliance with the License. # * # * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # * or http://www.opensolaris.org/os/licensing. # * See the License for the specific language governing permissions # * and limitations under the License. # * # * When distributing Covered Code, include this CDDL HEADER in each # * file and include the License file at usr/src/OPENSOLARIS.LICENSE. # * If applicable, add the following below this CDDL HEADER, with the # * fields enclosed by brackets "[]" replaced with your own identifying # * information: Portions Copyright [yyyy] [name of copyright owner] # snap_name () { SN=`date '+%S.%M.%H.%d.%m.%y'` echo "SNAPSHOT-"$SN } # ssh-keygen -t rsa # cat id_rsa.pub >> authorized_keys2 # scp id_rsa.pub remotehostname:/.ssh/remotehostname.key.pub # # In /etc/ssh/sshd_config # PermitRootLogin yes REMOTEHOST=va64-x2200b-gmp03 LOCALPOOL=zpool REMOTEPOOL=zpool_backup FS=fs1 REMOTEFS=sn1 # Unadjusted Interval is the wait between snapshots INTERVAL=60 integer ADJUSTED_INTERVAL ENCRYPT="-c blowfish" SNAP_NAME=`snap_name` # Take a snapshot zfs snapshot -r $LOCALPOOL/$FS@$SNAP_NAME if [ $? != 0 ] ; then echo "snapshot failed $SNAP_NAME" exit 1 fi # Test if the remote directory is already there ssh $REMOTEHOST ls /$REMOTEPOOL/$REMOTEFS 2>&1 > /dev/null # If it is not then do a full send/recv and wait, and wait, and wait, and wait if [ $? != 0 ] ; then printf "Full snapshot send/recv started : %s\n" "`date`" zfs send $LOCALPOOL/$FS@$SNAP_NAME | ssh $ENCRYPT $REMOTEHOST zfs recv -v $REMOTEPOOL/$REMOTEFS else zfs send -i $1 $LOCALPOOL/$FS@$SNAP_NAME | ssh $ENCRYPT $REMOTEHOST zfs recv -F -v $REMOTEPOOL/$REMOTEFS fi if [ $? != 0 ] ; then echo "send/recv failed $SNAP_NAME" exit 1 fi PREVIOUS_SN=$SNAP_NAME sleep 1 while true do echo "" SECONDS=0 SNAP_NAME=`snap_name` zfs snapshot -r $LOCALPOOL/$FS@$SNAP_NAME if [ $? != 0 ] ; then echo "snapshot failed $SNAP_NAME" exit 1 fi # Now apply the incremental printf "Incremental snapshot send/recv started : %s\n" "`date`" zfs send -i $PREVIOUS_SN $LOCALPOOL/$FS@$SNAP_NAME | ssh $ENCRYPT $REMOTEHOST zfs receive -v $REMOTEPOOL/$REMOTEFS if [ $? != 0 ] ; then echo "send/recv failed for $SNAP_NAME" exit 1 fi printf "snapshot send/recv completed : " if [ $SECONDS -ge $INTERVAL ] ; then echo "zfs send/recv too longer than $INTERVAL" echo "No point sleeping" echo "Review data rate vs sleep time (buy faster network!)" else ((ADJUSTED_INTERVAL=INTERVAL-SECONDS)) printf "zfs send/recv took %u seconds : " $SECONDS printf "Adjusted delay interval = %u seconds\n" $ADJUSTED_INTERVAL sleep $ADJUSTED_INTERVAL fi PREVIOUS_SN=$SNAP_NAME done