From owner-svn-src-user@FreeBSD.ORG Wed Apr 18 12:51:49 2012 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5758D106564A; Wed, 18 Apr 2012 12:51:49 +0000 (UTC) (envelope-from des@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4327E8FC1F; Wed, 18 Apr 2012 12:51:49 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q3ICpnH4032272; Wed, 18 Apr 2012 12:51:49 GMT (envelope-from des@svn.freebsd.org) Received: (from des@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q3ICpn8g032270; Wed, 18 Apr 2012 12:51:49 GMT (envelope-from des@svn.freebsd.org) Message-Id: <201204181251.q3ICpn8g032270@svn.freebsd.org> From: Dag-Erling Smorgrav Date: Wed, 18 Apr 2012 12:51:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r234419 - user/des/zfs-backup X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Apr 2012 12:51:49 -0000 Author: des Date: Wed Apr 18 12:51:48 2012 New Revision: 234419 URL: http://svn.freebsd.org/changeset/base/234419 Log: Support remote backups - both push and pull. Modified: user/des/zfs-backup/zfs-backup.sh Modified: user/des/zfs-backup/zfs-backup.sh ============================================================================== --- user/des/zfs-backup/zfs-backup.sh Wed Apr 18 12:50:13 2012 (r234418) +++ user/des/zfs-backup/zfs-backup.sh Wed Apr 18 12:51:48 2012 (r234419) @@ -48,20 +48,42 @@ fi if [ $# -ne 2 ] ; then error "usage: $0 src dst" fi -src="$1" -dst="$2" + +fqsrc="$1" +case $fqsrc in +*:*) + src="${fqsrc#*:}" + srczfs="ssh ${fqsrc%%:*} zfs" + ;; +*) + src="${fqsrc}" + srczfs="zfs" + ;; +esac + +fqdst="$2" +case $fqdst in +*:*) + dst="${fqdst#*:}" + dstzfs="ssh ${fqdst%%:*} zfs" + ;; +*) + dst="${fqdst}" + dstzfs="zfs" + ;; +esac # Check src / dst datasets -if ! zfs list "$src" >/dev/null 2>&1 ; then - error "'$src' is not a valid dataset" +if ! $srczfs list "$src" >/dev/null 2>&1 ; then + error "'$fqsrc' is not a valid dataset" fi -if ! zfs list "$dst" >/dev/null 2>&1 ; then - error "'$dst' is not a valid dataset" +if ! $dstzfs list "$dst" >/dev/null 2>&1 ; then + error "'$fqdst' is not a valid dataset" fi -if [ "$src" = "$dst" ] ; then +if [ "$fqsrc" = "$fqdst" ] ; then error "source and destination must be different datasets" fi -if [ "${src#$dst/}" != "$src" -o "${dst#$src/}" != "$dst" ] ; then +if [ "${fqsrc#$fqdst/}" != "$fqsrc" -o "${fqdst#$fqsrc/}" != "$fqdst" ] ; then error "source and destination must be non-overlapping datasets" fi case src in @@ -77,12 +99,12 @@ fi now=$(date +%Y%m%d-%H%M%S) beg=$(date +%s) this="bak-$now" -last=$(zfs list -t snapshot | cut -d' ' -f1 | grep "^$dst$sub@bak-" | sort | tail -1) +last=$($dstzfs list -t snapshot | cut -d' ' -f1 | grep "^$dst$sub@bak-" | sort | tail -1) if [ -z "$last" ] ; then # First time - info "It looks like this is the first backup from $src to $dst." \ - "Continuing will DESTROY the contents of $dst, including any" \ - "preexisting snapshots, and replace them with the contents of $src." + info "It looks like this is the first backup from $fqsrc to $fqdst." \ + "Continuing will DESTROY the contents of $fqdst, including any" \ + "preexisting snapshots, and replace them with the contents of $fqsrc." while :; do echo -n "Are you sure you want to proceed? (yes/no) " read answer @@ -95,17 +117,17 @@ if [ -z "$last" ] ; then ;; esac done - zfs snapshot -r "$src@$this" || error "snapshot failed" - zfs send $verbose -R "$src@$this" | - zfs receive $verbose -F -d -u "$dst" + $srczfs snapshot -r "$src@$this" || error "snapshot failed" + $srczfs send $verbose -R "$src@$this" | + $dstzfs receive $verbose -F -d -u "$dst" else # Subsequent times last="${last#*@}" - zfs list "$src@$last" >/dev/null || error "failed to determine last backup" - zfs snapshot -r "$src@$this" || error "snapshot failed" - zfs send $verbose -R -I "$src@$last" "$src@$this" | - zfs receive $verbose -F -d -u "$dst" - zfs destroy -r "$src@$last" + $srczfs list "$src@$last" >/dev/null || error "failed to determine last backup" + $srczfs snapshot -r "$src@$this" || error "snapshot failed" + $srczfs send $verbose -R -I "$src@$last" "$src@$this" | + $dstzfs receive $verbose -F -d -u "$dst" + $srczfs destroy -r "$src@$last" fi end=$(date +%s) -info "Backup from $src to $dst completed in $((end - beg)) seconds" +#info "Backup from $fqsrc to $fqdst completed in $((end - beg)) seconds"