mirror of
https://asciireactor.com/o4data/zfs-backup.git
synced 2024-11-25 00:05:07 +00:00
File updates and add function for creating datasets.
This commit is contained in:
parent
bdde2372bf
commit
4eb6470736
52
backup.sh
52
backup.sh
@ -1,25 +1,57 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
nodes_file="nodes.txt"
|
||||
### nodes.txt
|
||||
# <local hostname> <local ssh port> <this host's root zfs> <this host's user>
|
||||
# <remote host 1 address> <host 1 ssh port> <host 1 root zfs>
|
||||
# <remote host 2 address> <host 2 ssh port> <host 2 root zfs>
|
||||
# ...
|
||||
|
||||
datasets_file="datasets.txt"
|
||||
### datasets.txt
|
||||
# <dataset 1>
|
||||
# <dataset 1>/<dataset 1a>
|
||||
# <dataset 1>/<dataset 1b>
|
||||
# <dataset 2>
|
||||
# <dataset 2>/<dataset 2a>
|
||||
# <dataset 3>
|
||||
# ...
|
||||
|
||||
list_datasets()
|
||||
list_active_datasets()
|
||||
{
|
||||
zfs list | tail -n +2 | cut -d' ' -f1|grep ${BR_ROOT}
|
||||
}
|
||||
|
||||
read_datasets() {
|
||||
while read BR_REMOTE_ADDR BR_REMOTE_PORT BR_REMOTE_ROOT BR_REMOTE_USER; do
|
||||
case $BR_REMOTE_ADDR in
|
||||
\#*) continue;;
|
||||
esac
|
||||
if [ $BR_TEST_MODE = "TRUE" ]; then
|
||||
echo zfs send -R ${BR_ROOT}@${BR_NEW_SNAPSHOT}
|
||||
echo ssh -i ~/.ssh/id_rsa -o port=${BR_REMOTE_PORT} \
|
||||
${BR_REMOTE_USER}@${BR_REMOTE_ADDR} \
|
||||
zfs receive -vu ${BR_REMOTE_ROOT}
|
||||
else
|
||||
zfs send -R ${BR_ROOT}@${BR_NEW_SNAPSHOT} |
|
||||
ssh -i ~/.ssh/id_rsa -o port=${BR_REMOTE_PORT} \
|
||||
${BR_REMOTE_USER}@${BR_REMOTE_ADDR} \
|
||||
zfs receive -dvu ${BR_REMOTE_ROOT}
|
||||
fi
|
||||
done < ${datasets_file}
|
||||
}
|
||||
|
||||
# compare_datasets()
|
||||
|
||||
create_datasets() {
|
||||
# should compare_datasets and only create missing or possibly error.
|
||||
for dataset in `cat ${datasets_file}`; do
|
||||
zfs create -p ${BR_ROOT}/$dataset
|
||||
done
|
||||
for dataset in `cat ${datasets_file}`; do
|
||||
zfs create -p ${BR_ROOT}/$dataset
|
||||
done
|
||||
}
|
||||
|
||||
get_latest_snapshot()
|
||||
{
|
||||
zfs list -t snapshot |
|
||||
@ -32,17 +64,13 @@ get_latest_snapshot()
|
||||
setup_aggregator()
|
||||
{
|
||||
zfs allow -u ${BR_USER} send,snapshot,hold ${BR_ROOT}
|
||||
for dataset in `cat datasets.txt`; do
|
||||
zfs create -p ${BR_ROOT}/$dataset
|
||||
done
|
||||
create_datasets
|
||||
}
|
||||
|
||||
setup_mirror()
|
||||
{
|
||||
zfs create -p $BR_ROOT
|
||||
for dataset in `cat datasets.txt`; do
|
||||
zfs create -p ${BR_ROOT}/$dataset
|
||||
done
|
||||
create_datasets
|
||||
zfs allow -u ${BR_USER} send,snapshot,hold ${BR_ROOT}
|
||||
zfs allow -u ${BR_USER} \
|
||||
compression,mountpoint,receive,create,mount ${BR_ROOT}
|
||||
@ -61,7 +89,7 @@ create_snapshot()
|
||||
send_single_snapshot()
|
||||
{
|
||||
BR_NEW_SNAPSHOT=`get_latest_snapshot`
|
||||
tail -n +2 nodes.txt > sendnodes.tmp
|
||||
tail -n +2 ${nodes_file} > sendnodes.tmp
|
||||
while read BR_REMOTE_ADDR BR_REMOTE_PORT BR_REMOTE_ROOT BR_REMOTE_USER; do
|
||||
case $BR_REMOTE_ADDR in
|
||||
\#*) continue;;
|
||||
@ -119,13 +147,13 @@ while :; do
|
||||
shift
|
||||
done
|
||||
|
||||
read BR_HOST BR_PORT BR_ROOT BR_USER < nodes.txt
|
||||
read BR_HOST BR_PORT BR_ROOT BR_USER < ${nodes_file}
|
||||
|
||||
if [ ! -f nodes.txt ]; then echo "No nodes specified."; exit 2; fi
|
||||
if [ ! -f ${nodes_file} ]; then echo "No nodes specified."; exit 2; fi
|
||||
|
||||
### Command
|
||||
case "$1" in
|
||||
list) list_datasets ;;
|
||||
list) list_active_datasets ;;
|
||||
create) create_snapshot ;;
|
||||
setup-mirror) setup_mirror ;;
|
||||
send)
|
||||
|
Loading…
Reference in New Issue
Block a user