mirror of
https://asciireactor.com/o4data/zfs-backup.git
synced 2024-11-22 05:35:06 +00:00
Updated all run routines.
This commit is contained in:
parent
7c914b7a60
commit
b178bf3793
153
backup.sh
153
backup.sh
@ -9,11 +9,11 @@ nodes_file="nodes.txt"
|
|||||||
|
|
||||||
datasets_file="datasets.txt"
|
datasets_file="datasets.txt"
|
||||||
### datasets.txt
|
### datasets.txt
|
||||||
# <dataset 1> [remote dataset]
|
# <dataset 1> [options]
|
||||||
# <dataset 2> [remote dataset]
|
# <dataset 2> [options]
|
||||||
# <dataset 3> [remote dataset]
|
# <dataset 3> [options]
|
||||||
# ...
|
# ...
|
||||||
# recognized options: nosend nosnap(shot) remotezfs=<remote dataset name>
|
# recognized options: nosend nosnap(shot) remotezfs=<remote dset name>
|
||||||
|
|
||||||
if [ ! -f $nodes_file ]; then echo "No nodes specified."; exit 2; fi
|
if [ ! -f $nodes_file ]; then echo "No nodes specified."; exit 2; fi
|
||||||
if [ ! -f $datasets_file ]; then echo "No datasets specified."; exit 3; fi
|
if [ ! -f $datasets_file ]; then echo "No datasets specified."; exit 3; fi
|
||||||
@ -48,6 +48,34 @@ run_send_recv()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run_snapshot()
|
||||||
|
{
|
||||||
|
if [ $ZB_TEST_MODE = "TRUE" ]; then
|
||||||
|
echo zfs snapshot $ZFS_SNAPSHOT_OPTS $dset@$snapid
|
||||||
|
else
|
||||||
|
zfs snapshot $ZFS_SNAPSHOT_OPTS $dset@$snapid
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
run_allow()
|
||||||
|
{
|
||||||
|
if [ $ZB_TEST_MODE = "TRUE" ]; then
|
||||||
|
echo zfs allow -u $LOCAL_USER $ORIGIN_PERMS $dset
|
||||||
|
else
|
||||||
|
zfs allow -u $LOCAL_USER $ORIGIN_PERMS $dset
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
run_remote()
|
||||||
|
{
|
||||||
|
ssh_cmd="ssh $SSH_SEND_OPTS -o port=$port $user@$addr"
|
||||||
|
if [ $ZB_TEST_MODE = "TRUE" ]; then
|
||||||
|
echo $ssh_cmd $remote_cmd
|
||||||
|
else
|
||||||
|
$ssh_cmd $remote_cmd
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
set_compression() {
|
set_compression() {
|
||||||
case $SEND_COMPRESSED in
|
case $SEND_COMPRESSED in
|
||||||
[tTyY]*) ZFS_SEND_OPTS="$ZFS_SEND_OPTS -c"
|
[tTyY]*) ZFS_SEND_OPTS="$ZFS_SEND_OPTS -c"
|
||||||
@ -57,8 +85,8 @@ set_compression() {
|
|||||||
|
|
||||||
populate_datasets()
|
populate_datasets()
|
||||||
{
|
{
|
||||||
while read dataset dataset_options; do
|
while read dset dataset_options; do
|
||||||
case $dataset in
|
case $dset in
|
||||||
\#*) continue;;
|
\#*) continue;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@ -74,32 +102,32 @@ populate_datasets()
|
|||||||
;;
|
;;
|
||||||
"remotezfs="*)
|
"remotezfs="*)
|
||||||
remotezfs=`echo $option|cut -d'=' -f2`
|
remotezfs=`echo $option|cut -d'=' -f2`
|
||||||
dataset="$dataset:$remotezfs"
|
dset="$dset:$remotezfs"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $send_dataset ]; then
|
if [ $send_dataset ]; then
|
||||||
SEND_DATASETS="$SEND_DATASETS $dataset"
|
SEND_DATASETS="$SEND_DATASETS $dset"
|
||||||
debug "Enabled send for $dataset."
|
debug "Enabled send for $dset."
|
||||||
fi
|
fi
|
||||||
if [ $snapshot_dataset ]; then
|
if [ $snapshot_dataset ]; then
|
||||||
SNAPSHOT_DATASETS="$SNAPSHOT_DATASETS $dataset"
|
SNAPSHOT_DATASETS="$SNAPSHOT_DATASETS $dset"
|
||||||
debug "Enabled snapshot for $dataset."
|
debug "Enabled snapshot for $dset."
|
||||||
fi
|
fi
|
||||||
done < datasets.txt
|
done < datasets.txt
|
||||||
}
|
}
|
||||||
|
|
||||||
list_datasets()
|
list_datasets()
|
||||||
{
|
{
|
||||||
for dataset in $SEND_DATASETS; do
|
for dset in $SEND_DATASETS; do
|
||||||
dataset=`echo $dataset|cut -d: -f1`
|
dset=`echo $dset|cut -d: -f1`
|
||||||
zfs list -H $dataset
|
zfs list -H $dset
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
list_remote_datasets() {
|
list_remote_datasets() {
|
||||||
while read addr user ssh_port zroot speed; do
|
while read addr user port zroot speed; do
|
||||||
echo "=== $user@$addr $zroot ==="
|
echo "=== $user@$addr $zroot ==="
|
||||||
if [ $zroot ]; then
|
if [ $zroot ]; then
|
||||||
case $zroot in
|
case $zroot in
|
||||||
@ -107,22 +135,19 @@ list_remote_datasets() {
|
|||||||
*) zroot="$zroot/" ;;
|
*) zroot="$zroot/" ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
run_cmd="
|
remote_cmd="
|
||||||
sh -c 'for dataset in $SEND_DATASETS; do
|
sh -c 'for dset in $SEND_DATASETS; do
|
||||||
dataset=`echo \\$dataset|cut -d: -f2`
|
dset=`echo \\$dset|cut -d: -f2`
|
||||||
zfs list -H $zroot\$dataset;
|
zfs list -H $zroot\$dset;
|
||||||
done'"
|
done'
|
||||||
if [ $ZB_TEST_MODE = "TRUE" ]; then
|
"
|
||||||
echo ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr $run_cmd
|
run_remote
|
||||||
else
|
|
||||||
ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr $run_cmd
|
|
||||||
fi
|
|
||||||
done < sendnodes.tmp
|
done < sendnodes.tmp
|
||||||
}
|
}
|
||||||
|
|
||||||
get_latest_snapshot()
|
get_latest_snapshot()
|
||||||
{
|
{
|
||||||
zfs list -t snapshot $dataset | tail -n1 | cut -d'@' -f2 | cut -d' ' -f 1
|
zfs list -t snapshot $dset | tail -n1 | cut -d'@' -f2 | cut -d' ' -f 1
|
||||||
}
|
}
|
||||||
|
|
||||||
get_latest_remote_snapshot()
|
get_latest_remote_snapshot()
|
||||||
@ -133,26 +158,22 @@ get_latest_remote_snapshot()
|
|||||||
*) zroot="$zroot/" ;;
|
*) zroot="$zroot/" ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \
|
remote_cmd="zfs list -t snapshot $zroot$dset|tail -n1|cut -d'@' -f2|cut -d' ' -f 1"
|
||||||
"zfs list -t snapshot $zroot$dataset |
|
run_remote
|
||||||
tail -n1|cut -d'@' -f2|cut -d' ' -f 1"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zfs_allow_origin()
|
zfs_allow_origin()
|
||||||
{
|
{
|
||||||
for dataset in $SEND_DATASETS; do
|
for dset in $SEND_DATASETS; do
|
||||||
dataset=`echo $dataset|cut -d: -f1`
|
dset=`echo $dset|cut -d: -f1`
|
||||||
if [ $ZB_TEST_MODE = "TRUE" ]; then
|
run_allow
|
||||||
echo zfs allow -u $LOCAL_USER $ORIGIN_PERMS $dataset
|
|
||||||
else
|
|
||||||
zfs allow -u $LOCAL_USER $ORIGIN_PERMS $dataset
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
zfs_allow_mirrors()
|
zfs_allow_mirrors()
|
||||||
{
|
{
|
||||||
while read addr user ssh_port zroot speed; do
|
while read addr user port zroot speed; do
|
||||||
echo "=== $user@$addr $zroot ==="
|
echo "=== $user@$addr $zroot ==="
|
||||||
if [ $zroot ]; then
|
if [ $zroot ]; then
|
||||||
case $zroot in
|
case $zroot in
|
||||||
@ -161,34 +182,26 @@ zfs_allow_mirrors()
|
|||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
remote_cmd="
|
remote_cmd="
|
||||||
for dataset in $SEND_DATASETS; do
|
for dset in $SEND_DATASETS; do
|
||||||
dataset=`echo \\$dataset|cut -d: -f2`
|
dset=`echo \\$dset|cut -d: -f2`
|
||||||
zfs allow -u $user $MIRROR_PERMS $zroot\$dataset
|
zfs allow -u $user $MIRROR_PERMS $zroot\$dset
|
||||||
done
|
done
|
||||||
"
|
"
|
||||||
if [ $ZB_TEST_MODE = "TRUE" ]; then
|
run_remote
|
||||||
echo ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr $remote_cmd
|
|
||||||
else
|
|
||||||
ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr $remote_cmd
|
|
||||||
fi
|
|
||||||
done < sendnodes.tmp
|
done < sendnodes.tmp
|
||||||
}
|
}
|
||||||
|
|
||||||
create_snapshots()
|
create_snapshots()
|
||||||
{
|
{
|
||||||
snapshot_id="`date -I`-`date +%s`-$LOCAL_TZ"
|
snapid="`date -I`-`date +%s`-$LOCAL_TZ"
|
||||||
for dataset in $SNAPSHOT_DATASETS; do
|
for dset in $SNAPSHOT_DATASETS; do
|
||||||
if [ $ZB_TEST_MODE = "TRUE" ]; then
|
run_snapshot
|
||||||
echo zfs snapshot $ZFS_SNAPSHOT_OPTS $dataset@$snapshot_id
|
|
||||||
else
|
|
||||||
zfs snapshot $ZFS_SNAPSHOT_OPTS $dataset@$snapshot_id
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
send_latest()
|
send_latest()
|
||||||
{
|
{
|
||||||
while read addr user ssh_port zroot speed; do
|
while read addr user port zroot speed; do
|
||||||
echo "=== $user@$addr $zroot ==="
|
echo "=== $user@$addr $zroot ==="
|
||||||
if [ $zroot ]; then
|
if [ $zroot ]; then
|
||||||
case $zroot in
|
case $zroot in
|
||||||
@ -196,15 +209,14 @@ send_latest()
|
|||||||
*) zroot="$zroot/" ;;
|
*) zroot="$zroot/" ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
for dataset in $SEND_DATASETS; do
|
for dset in $SEND_DATASETS; do
|
||||||
remote_dataset=`echo $dataset|cut -d: -f2`
|
rset=`echo $dset|cut -d: -f2`
|
||||||
dataset=`echo $dataset|cut -d: -f1`
|
dset=`echo $dset|cut -d: -f1`
|
||||||
debug "Processing $dataset (remote $remote_dataset)."
|
debug "Processing $dset (remote $rset)."
|
||||||
origin_snapshot=`get_latest_snapshot $dataset`
|
snap1=`get_latest_snapshot $dset`
|
||||||
send_cmd="zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot"
|
send_cmd="zfs send $ZFS_SEND_OPTS $dset@$snap1"
|
||||||
pv_cmd="pv -qL ${speed:-$DEF_SPEED}"
|
pv_cmd="pv -qL ${speed:-$DEF_SPEED}"
|
||||||
recv_cmd="ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \
|
recv_cmd="ssh $SSH_SEND_OPTS -o port=$port $user@$addr zfs recv $ZFS_RECV_OPTS $zroot$rset"
|
||||||
zfs recv $ZFS_RECV_OPTS $zroot$remote_dataset"
|
|
||||||
run_send_recv
|
run_send_recv
|
||||||
done
|
done
|
||||||
done < sendnodes.tmp
|
done < sendnodes.tmp
|
||||||
@ -212,7 +224,7 @@ send_latest()
|
|||||||
|
|
||||||
send_increment()
|
send_increment()
|
||||||
{
|
{
|
||||||
while read addr user ssh_port zroot speed; do
|
while read addr user port zroot speed; do
|
||||||
echo "=== $user@$addr $zroot ==="
|
echo "=== $user@$addr $zroot ==="
|
||||||
if [ $zroot ]; then
|
if [ $zroot ]; then
|
||||||
case $zroot in
|
case $zroot in
|
||||||
@ -220,16 +232,15 @@ send_increment()
|
|||||||
*) zroot="$zroot/" ;;
|
*) zroot="$zroot/" ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
for dataset in $SEND_DATASETS; do
|
for dset in $SEND_DATASETS; do
|
||||||
remote_dataset=`echo $dataset|cut -d: -f2`
|
rset=`echo $dset|cut -d: -f2`
|
||||||
dataset=`echo $dataset|cut -d: -f1`
|
dset=`echo $dset|cut -d: -f1`
|
||||||
origin_snapshot=`get_latest_snapshot`
|
snap1=`get_latest_snapshot`
|
||||||
remote_snapshot=`get_latest_remote_snapshot`
|
snap0=`get_latest_remote_snapshot`
|
||||||
send_cmd="zfs send $ZFS_SEND_OPTS -i $dataset@$remote_snapshot \
|
send_cmd="zfs send $ZFS_SEND_OPTS -i $dset@$snap0 $dset@$snap1"
|
||||||
$dataset@$origin_snapshot"
|
|
||||||
pv_cmd="pv -qL ${speed:-$DEF_SPEED}"
|
pv_cmd="pv -qL ${speed:-$DEF_SPEED}"
|
||||||
recv_cmd="ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \
|
recv_cmd="ssh $SSH_SEND_OPTS -o port=$port $user@$addr \
|
||||||
zfs recv $ZFS_RECV_OPTS $zroot$remote_dataset"
|
zfs recv $ZFS_RECV_OPTS $zroot$rset"
|
||||||
run_send_recv
|
run_send_recv
|
||||||
done
|
done
|
||||||
done < sendnodes.tmp
|
done < sendnodes.tmp
|
||||||
|
Loading…
Reference in New Issue
Block a user