equal
deleted
inserted
replaced
|
1 #!/bin/sh -e |
|
2 # Based on: http://www.cuddletech.com/blog/pivot/entry.php?id=989 |
|
3 # |
|
4 # This script differs from original Zynk that uses -R and destination dataset, |
|
5 # not filesystem. |
|
6 # |
|
7 ## ZYNK: The Zuper Zimple ZFS Sync (Replication) Tool |
|
8 ## Form: zynk local/dataset root@remote.host destination/dataset |
|
9 |
|
10 # Please note: The reason this is so simple is because there is no error |
|
11 # checking, reporting, or cleanup. |
|
12 # |
|
13 # In the event that something goes wonkey, you'll manually need to fix the |
|
14 # snapshots and modify or remove the run datafile which contains the most |
|
15 # recent snapshot name. |
|
16 # |
|
17 # Furthermore, this absolutely relies on the GNU version of 'date' in order to |
|
18 # get epoch time. |
|
19 # |
|
20 # Before using, make sure you've: |
|
21 # 1. distributed your SSH key to the remote host and can ssh without |
|
22 # password; |
|
23 # 2. delegated zfs rights to the user performing zynk. |
|
24 # |
|
25 |
|
26 if [ -z "$3" ]; then |
|
27 echo "Usage: zynk local/dataset remote.host destination/dataset" |
|
28 exit 1 |
|
29 fi |
|
30 |
|
31 DATE=`date +%s` |
|
32 if [ "$DATE" = "%s" ]; then |
|
33 echo "Must use GNU Date, please install and modify script." |
|
34 exit 2 |
|
35 fi |
|
36 |
|
37 LOCALFS=$1 |
|
38 HOST=$2 |
|
39 REMOTEFS=$3 |
|
40 RUNF=`echo $LOCALFS-$HOST-$REMOTEFS|sed -e 's{[@/]{-{g'` |
|
41 CUR=`date '+%F-%H%M'` |
|
42 |
|
43 TYPE="Full" |
|
44 SEND_OPTS="" |
|
45 |
|
46 if [ -e $RUNF ]; then |
|
47 TYPE="Incremental" |
|
48 SEND_OPTS="-i $LOCALFS@`cat $RUNF`" |
|
49 fi |
|
50 |
|
51 echo "$TYPE started at `date`" |
|
52 zfs snapshot -r $LOCALFS@$CUR |
|
53 zfs send -v -R $SEND_OPTS $LOCALFS@$CUR | ssh $HOST zfs recv -F -d $REMOTEFS |
|
54 echo $CUR > $RUNF |
|
55 echo "$TYPE complete at `date`" |