Added an already running check
[zfs-nexenta/.git] / zfs-restore-all
1 #!/bin/bash
2
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.
6
7 # source our configuration 
8 config="${0%/*}/zfs-scripts.conf"
9 [ -e "${config}.dist" ] && . ${config}.dist
10 [ -e "${config}" ] && . ${config}
11
12 # Setup some default values
13 logfile="$logdir/zfs-restore-all.log"
14
15 # Setup our output
16 if [[ -z "$SCRIPT_UNDER_TEST" ]]; then
17     exec >> $logfile 2>&1
18 fi
19
20 cleanup_and_exit() {
21   exit 1
22 }
23 trap cleanup_and_exit INT
24
25
26 # See if the user has a specific pool to restore in mind
27 restore_pool=$1
28
29 # Restore every ZFS filesystem we were told to replicate 
30 echo `date` ZFS restore started
31
32 # For each filesystem we are supposed to restore, do it
33 for filesystem in $filesystems_to_replicate; do
34   dst_pool=${filesystem%%/*}
35   dst_fs=${filesystem#*/}
36   # Check to make sure the dst filesystem does not exist
37   ssh $remote "$zfs list ${dst_pool}/${dst_fs}" > /dev/null 2>&1
38   if [ $? != 0 ]; then
39     echo "$filesystem" | grep -q "$restore_pool" 
40     if [ $? == 0 ]; then
41       # This filesystem matches our restore pool pattern 
42       echo `date` Restoring $filesystem to $remote
43       zfs-restore $local_pool $filesystem $dst_pool $dst_fs $remote
44     fi
45   else
46     echo "-I- Filesystem already exists on destination. Skipping: $filesystem"
47   fi 
48 done
49
50 # All done
51 echo `date` ZFS restore complete
52