diff --git a/.gitignore b/.gitignore index 3c87c1f..2ad8044 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ datasets.txt nodes.txt old-snapshot.txt +sendnodes.tmp \ No newline at end of file diff --git a/backup.sh b/backup.sh index 4cc9fb0..6aded5b 100755 --- a/backup.sh +++ b/backup.sh @@ -17,9 +17,10 @@ datasets_file="datasets.txt" if [ ! -f $nodes_file ]; then echo "No nodes specified."; exit 2; fi if [ ! -f $datasets_file ]; then echo "No datasets specified."; exit 3; fi -ZFS_SEND_OPTS="-R" +ZFS_SEND_OPTS="-vpRLe" ZFS_SNAPSHOT_OPTS="-r" ZFS_RECV_OPTS="-svu" +SSH_SEND_OPTS="-Ti ~/.ssh/id_rsa" read LOCAL_HOST LOCAL_USER LOCAL_PORT LOCAL_TZ SEND_COMPRESSED < $nodes_file case $SEND_COMPRESSED in @@ -27,7 +28,7 @@ case $SEND_COMPRESSED in esac ORIGIN_PERMS="send,snapshot,hold" -MIRROR_PERMS="compression,receive,create,mount,mountpoint" +MIRROR_PERMS="compression,receive,create,mount,mountpoint,readonly,jailed" SEND_DATASETS="" SNAPSHOT_DATASETS="" @@ -70,12 +71,12 @@ list_remote_datasets() { esac fi if [ $BG_TEST_MODE = "TRUE" ]; then - echo ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr\ + echo ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr\ "sh -c 'for dataset in $SEND_DATASETS; do zfs list -H $zroot\$dataset; done'" else - ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ + ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ "sh -c 'for dataset in $SEND_DATASETS; do zfs list -H $zroot\$dataset; done';" @@ -96,7 +97,7 @@ get_latest_remote_snapshot() *) zroot="$zroot/" ;; esac fi - ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ + ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ "zfs list -t snapshot $zroot\$dataset | tail -n1|cut -d'@' -f2|cut -d' ' -f 1" } @@ -123,12 +124,12 @@ zfs_allow_mirrors() esac fi if [ $BG_TEST_MODE = "TRUE" ]; then - echo ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ + echo ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ "for dataset in $SEND_DATASETS; do zfs allow -u $user $MIRROR_PERMS $zroot\$dataset done" else - ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ + ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ "for dataset in $SEND_DATASETS; do zfs allow -u $user $MIRROR_PERMS $zroot\$dataset done" @@ -162,11 +163,11 @@ send_latest() origin_snapshot=`get_latest_snapshot $dataset` if [ $BG_TEST_MODE = "TRUE" ]; then echo zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot \| \ - ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ + ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ zfs recv $ZFS_RECV_OPTS $zroot$dataset else zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot | - ssh -i ~/.ssh/id_rsa -o port=$ssh_port \ + ssh $SSH_SEND_OPTS -o port=$ssh_port \ $user@$addr \ zfs recv $ZFS_RECV_OPTS $zroot$dataset fi @@ -191,13 +192,13 @@ send_increment() echo zfs send $ZFS_SEND_OPTS \ -i $dataset@$remote_snapshot \ $dataset@$origin_snapshot \| \ - ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ + ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ zfs recv $ZFS_RECV_OPTS $zroot$dataset else zfs send $ZFS_SEND_OPTS \ -i $dataset@$remote_snapshot \ $dataset@$origin_snapshot | - ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \ + ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ zfs recv $ZFS_RECV_OPTS $zroot$dataset fi done