Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 Jul 2014 13:14:16 +0100
From:      Mike Clarke <jmc-freebsd2@milibyte.co.uk>
To:        freebsd-questions@freebsd.org
Subject:   Backing up zfs system to external disk
Message-ID:  <1947386.pOQVzt1YdP@curlew.lan>

next in thread | raw e-mail | index | archive | help

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1947386.pOQVzt1YdP>