3 # Author: Alan J. Pippin
4 # Description: This script calls zfs-restore for each filesystem needing
5 # to be restored (that was formerly replicated here) to another ZFS pool.
7 # source our configuration
8 config="${0%/*}/zfs-scripts.conf"
9 [ -e "${config}.dist" ] && . ${config}.dist
10 [ -e "${config}" ] && . ${config}
12 # Setup some default values
13 logfile="$logdir/zfs-restore-all.log"
16 if [[ -z "$SCRIPT_UNDER_TEST" ]]; then
23 trap cleanup_and_exit INT
25 # See if the user has a specific pool to restore in mind
28 # Restore every ZFS filesystem we were told to replicate
29 echo `date` ZFS restore started
31 # For each filesystem we are supposed to restore, do it
32 for filesystem in $filesystems_to_replicate; do
33 dst_pool=${filesystem%%/*}
34 dst_fs=${filesystem#*/}
35 # Check to make sure the dst filesystem does not exist
36 if [[ $remote = "localhost" ]]; then
37 $ssh $remote $zfs list ${dst_pool}/${dst_fs} > /dev/null 2>&1
39 $zfs list ${dst_pool}/${dst_fs} > /dev/null 2>&1
42 echo "$filesystem" | grep -q "$restore_pool"
44 # This filesystem matches our restore pool pattern
45 echo `date` Restoring $filesystem to $remote
46 zfs-restore $backup_pool $filesystem $dst_pool $dst_fs $remote
49 echo "-I- Filesystem already exists on destination. Skipping: $filesystem"
54 echo `date` ZFS restore complete