mirror of
https://asciireactor.com/o4data/zfs-backup.git
synced 2024-11-22 04:15:05 +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"
|
ORIGIN_PERMS="send,snapshot,hold"
|
||||||
MIRROR_PERMS="compression,receive,create"
|
MIRROR_PERMS="compression,receive,create"
|
||||||
|
|
||||||
GRAPH_DATASETS_RAW=`cat $datasets_file`
|
SEND_DATASETS=""
|
||||||
GRAPH_DATASETS=`for dataset in $GRAPH_DATASETS_RAW; do
|
SNAPSHOT_DATASETS=""
|
||||||
|
while read dataset dataset_options; do
|
||||||
case $dataset in
|
case $dataset in
|
||||||
\#*) continue;;
|
\#*) continue;;
|
||||||
esac
|
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()
|
list_datasets()
|
||||||
{
|
{
|
||||||
for dataset in $GRAPH_DATASETS; do
|
for dataset in $SEND_DATASETS; do
|
||||||
zfs list -H $dataset
|
zfs list -H $dataset
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@ -49,12 +65,12 @@ list_remote_datasets() {
|
|||||||
echo "=== $user@$addr $zroot ==="
|
echo "=== $user@$addr $zroot ==="
|
||||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||||
echo ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr\
|
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;
|
do zfs list -H $zroot/\$dataset;
|
||||||
done'"
|
done'"
|
||||||
else
|
else
|
||||||
ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \
|
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;
|
do zfs list -H $zroot/\$dataset;
|
||||||
done';"
|
done';"
|
||||||
fi
|
fi
|
||||||
@ -75,7 +91,7 @@ get_latest_remote_snapshot()
|
|||||||
|
|
||||||
zfs_allow_origin()
|
zfs_allow_origin()
|
||||||
{
|
{
|
||||||
for dataset in $GRAPH_DATASETS; do
|
for dataset in $SEND_DATASETS; do
|
||||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||||
echo zfs allow -u $LOCAL_USER $ORIGIN_PERMS $dataset
|
echo zfs allow -u $LOCAL_USER $ORIGIN_PERMS $dataset
|
||||||
else
|
else
|
||||||
@ -90,12 +106,12 @@ zfs_allow_mirrors()
|
|||||||
echo "=== $user@$addr $zroot ==="
|
echo "=== $user@$addr $zroot ==="
|
||||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||||
echo ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \
|
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
|
zfs allow -u $user $MIRROR_PERMS $zroot/\$dataset
|
||||||
done"
|
done"
|
||||||
else
|
else
|
||||||
ssh -i ~/.ssh/id_rsa -o port=$ssh_port $user@$addr \
|
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
|
zfs allow -u $user $MIRROR_PERMS $zroot/\$dataset
|
||||||
done"
|
done"
|
||||||
fi
|
fi
|
||||||
@ -105,7 +121,7 @@ zfs_allow_mirrors()
|
|||||||
create_snapshots()
|
create_snapshots()
|
||||||
{
|
{
|
||||||
snapshot_id="`date -I`-`date +%s`-$LOCAL_TZ"
|
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
|
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||||
echo zfs snapshot $ZFS_SNAPSHOT_OPTS $dataset@$snapshot_id
|
echo zfs snapshot $ZFS_SNAPSHOT_OPTS $dataset@$snapshot_id
|
||||||
else
|
else
|
||||||
@ -118,7 +134,7 @@ send_latest()
|
|||||||
{
|
{
|
||||||
while read addr user ssh_port zroot; do
|
while read addr user ssh_port zroot; do
|
||||||
echo "=== $user@$addr $zroot ==="
|
echo "=== $user@$addr $zroot ==="
|
||||||
for dataset in $GRAPH_DATASETS; do
|
for dataset in $SEND_DATASETS; do
|
||||||
origin_snapshot=`get_latest_snapshot $dataset`
|
origin_snapshot=`get_latest_snapshot $dataset`
|
||||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||||
echo zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot \| \
|
echo zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot \| \
|
||||||
@ -138,7 +154,7 @@ send_increment()
|
|||||||
{
|
{
|
||||||
while read addr user ssh_port zroot; do
|
while read addr user ssh_port zroot; do
|
||||||
echo "=== $user@$addr $zroot ==="
|
echo "=== $user@$addr $zroot ==="
|
||||||
for dataset in $GRAPH_DATASETS; do
|
for dataset in $SEND_DATASETS; do
|
||||||
origin_snapshot=`get_latest_snapshot`
|
origin_snapshot=`get_latest_snapshot`
|
||||||
remote_snapshot=`get_latest_remote_snapshot`
|
remote_snapshot=`get_latest_remote_snapshot`
|
||||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user