mirror of
https://asciireactor.com/o4data/zfs-backup.git
synced 2024-11-21 19:25:06 +00:00
Added option handling for datasets.
This commit is contained in:
parent
b357e39996
commit
98b09fe806
42
backup.sh
42
backup.sh
@ -29,17 +29,33 @@ esac
|
||||
ORIGIN_PERMS="send,snapshot,hold"
|
||||
MIRROR_PERMS="compression,receive,create"
|
||||
|
||||
GRAPH_DATASETS_RAW=`cat $datasets_file`
|
||||
GRAPH_DATASETS=`for dataset in $GRAPH_DATASETS_RAW; do
|
||||
SEND_DATASETS=""
|
||||
SNAPSHOT_DATASETS=""
|
||||
while read dataset dataset_options; do
|
||||
case $dataset in
|
||||
\#*) continue;;
|
||||
esac
|
||||
echo -n "$dataset "
|
||||
done`
|
||||
|
||||
snapshot_dataset="yes"
|
||||
send_dataset="yes"
|
||||
case $dataset_options in
|
||||
*"nosnap"* ) snapshot_dataset="";;
|
||||
esac
|
||||
case $dataset_options in
|
||||
*"nosend"* ) send_dataset="";;
|
||||
esac
|
||||
|
||||
if [ $send_dataset ]; then
|
||||
SEND_DATASETS="$SEND_DATASETS $dataset"
|
||||
fi
|
||||
if [ $snapshot_dataset ]; then
|
||||
SNAPSHOT_DATASETS="$SNAPSHOT_DATASETS $dataset"
|
||||
fi
|
||||
done < datasets.txt
|
||||
|
||||
list_datasets()
|
||||
{
|
||||
for dataset in $GRAPH_DATASETS; do
|
||||
for dataset in $SEND_DATASETS; do
|
||||
zfs list -H $dataset
|
||||
done
|
||||
}
|
||||
@ -49,12 +65,12 @@ list_remote_datasets() {
|
||||
echo "=== $user@$addr $zroot ==="
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
echo ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr\
|
||||
"sh -c 'for dataset in $GRAPH_DATASETS;
|
||||
"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 \
|
||||
"sh -c 'for dataset in $GRAPH_DATASETS;
|
||||
"sh -c 'for dataset in $SEND_DATASETS;
|
||||
do zfs list -H $zroot/\$dataset;
|
||||
done';"
|
||||
fi
|
||||
@ -75,7 +91,7 @@ get_latest_remote_snapshot()
|
||||
|
||||
zfs_allow_origin()
|
||||
{
|
||||
for dataset in $GRAPH_DATASETS; do
|
||||
for dataset in $SEND_DATASETS; do
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
echo zfs allow -u $LOCAL_USER $ORIGIN_PERMS $dataset
|
||||
else
|
||||
@ -90,12 +106,12 @@ zfs_allow_mirrors()
|
||||
echo "=== $user@$addr $zroot ==="
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
echo ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \
|
||||
"for dataset in $GRAPH_DATASETS; do
|
||||
"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 \
|
||||
"for dataset in $GRAPH_DATASETS; do
|
||||
"for dataset in $SEND_DATASETS; do
|
||||
zfs allow -u $user $MIRROR_PERMS $zroot/\$dataset
|
||||
done"
|
||||
fi
|
||||
@ -105,7 +121,7 @@ zfs_allow_mirrors()
|
||||
create_snapshots()
|
||||
{
|
||||
snapshot_id="`date -I`-`date +%s`-$LOCAL_TZ"
|
||||
for dataset in $GRAPH_DATASETS; do
|
||||
for dataset in $SNAPSHOT_DATASETS; do
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
echo zfs snapshot $ZFS_SNAPSHOT_OPTS $dataset@$snapshot_id
|
||||
else
|
||||
@ -118,7 +134,7 @@ send_latest()
|
||||
{
|
||||
while read addr user ssh_port zroot; do
|
||||
echo "=== $user@$addr $zroot ==="
|
||||
for dataset in $GRAPH_DATASETS; do
|
||||
for dataset in $SEND_DATASETS; do
|
||||
origin_snapshot=`get_latest_snapshot $dataset`
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
echo zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot \| \
|
||||
@ -138,7 +154,7 @@ send_increment()
|
||||
{
|
||||
while read addr user ssh_port zroot; do
|
||||
echo "=== $user@$addr $zroot ==="
|
||||
for dataset in $GRAPH_DATASETS; do
|
||||
for dataset in $SEND_DATASETS; do
|
||||
origin_snapshot=`get_latest_snapshot`
|
||||
remote_snapshot=`get_latest_remote_snapshot`
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
|
Loading…
Reference in New Issue
Block a user