From owner-freebsd-questions@FreeBSD.ORG Sat Jul 26 12:17:32 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DCA12F3B for ; Sat, 26 Jul 2014 12:17:32 +0000 (UTC) Received: from avasout07.plus.net (avasout07.plus.net [84.93.230.235]) by mx1.freebsd.org (Postfix) with ESMTP id 76309263A for ; Sat, 26 Jul 2014 12:17:31 +0000 (UTC) Received: from curlew.milibyte.co.uk ([84.92.153.232]) by avasout07 with smtp id X0EJ1o007516WCc010EL6U; Sat, 26 Jul 2014 13:14:20 +0100 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=ANQ+opto c=1 sm=1 tr=0 a=lfSX4pPLp9EkufIcToJk/A==:117 a=lfSX4pPLp9EkufIcToJk/A==:17 a=D7rCoLxHAAAA:8 a=0Bzu9jTXAAAA:8 a=_gelNhxkGRwA:10 a=siBcfH3C_HYA:10 a=ZTb9aqGL9YkA:10 a=8nJEP1OIZ-IA:10 a=wLvYfUUl34cXeDXSANkA:9 a=wPNLvfGTeEIA:10 Received: from curlew.lan ([192.168.1.13]) by curlew.milibyte.co.uk with esmtp (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1XB0rh-0000is-Kr for freebsd-questions@freebsd.org; Sat, 26 Jul 2014 13:14:18 +0100 From: Mike Clarke To: freebsd-questions@freebsd.org Date: Sat, 26 Jul 2014 13:14:16 +0100 Message-ID: <1947386.pOQVzt1YdP@curlew.lan> User-Agent: KMail/4.12.5 (FreeBSD/9.1-RELEASE-p17; KDE/4.12.5; amd64; ; ) MIME-Version: 1.0 X-SA-Exim-Connect-IP: 192.168.1.13 X-SA-Exim-Mail-From: jmc-freebsd2@milibyte.co.uk X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on curlew.lan X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 Subject: Backing up zfs system to external disk Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="iso-8859-1" X-SA-Exim-Version: 4.2 X-SA-Exim-Scanned: Yes (on curlew.milibyte.co.uk) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Jul 2014 12:17:32 -0000 I've put together a script that backs up my zfs system to a zfs pool on an external ESATA drive. The script imports the backup pool with the -N option to avoid mounting filesystems on top of the running system, updates the backup pool to the latest snapshot with zfs send | zfs receive and then exports the backup pool. This normally works fine except in the rare cases when the system is shut down or crashes while the backup pool is still imported. If this happens then problems arise on the next reboot because filesystems will be mounted from both the system and backup pools using identical mountpoints. I tried creating the backup pool with the "-m none" option to avoid this but it didn't help. It only appears to apply to datasets created with "zfs create" - datasets resulting from "zfs receive" retain their original mountpoints. As a workaround I've created the following rc script which checks for and exports the backup pool before the local filesystems are mounted and seems to work OK. Since this isn't part of the base system I ought to put it in /usr/local/etc/rc.d but it needs to run before /usr is mounted so I had to put it in /etc/rc.d. I was wondering if there was a better way of solving this problem without breaking to the normal file system hierarchy? 8< - 8< - 8< - 8< - 8< - 8< - 8< - 8< - 8< -8< - 8< - #!/bin/sh # BEFORE: zfs # REQUIRE: root . /etc/rc.subr name=check_esata rcvar=check_esata_enable start_cmd="${name}_start" stop_cmd=":" load_rc_config $name : ${check_esata_enable:=yes} : ${check_esata_pool:=esata} check_esata_start() { echo "Checking esata backup pool" if zpool list $check_esata_pool 1>/dev/null 2>&1 then echo "Exporting $check_esata_pool" zpool export $check_esata_pool zpool list fi } run_rc_command "$1" -- Mike Clarke