mirror of
https://asciireactor.com/o4data/zfs-backup.git
synced 2024-11-22 08:25:05 +00:00
Updates up to first successful send.
This commit is contained in:
parent
cc9357d43a
commit
36caad4ba5
79
backup.sh
Executable file → Normal file
79
backup.sh
Executable file → Normal file
@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
### nodes.txt
|
### nodes.txt
|
||||||
# localhost 22 <this host's root zfs> <this host's user>
|
# <local hostname> <local ssh port> <this host's root zfs> <this host's user>
|
||||||
# <remote host 1 address> <host 1 port> <host 1 root zfs>
|
# <remote host 1 address> <host 1 ssh port> <host 1 root zfs>
|
||||||
# <remote host 2 address> <host 2 port> <host 2 root zfs>
|
# <remote host 2 address> <host 2 ssh port> <host 2 root zfs>
|
||||||
# ...
|
# ...
|
||||||
|
|
||||||
### datasets.txt (Only required for aggregator setup.)
|
### datasets.txt (Only required for aggregator setup.)
|
||||||
@ -15,11 +15,7 @@
|
|||||||
# <dataset 3>
|
# <dataset 3>
|
||||||
# ...
|
# ...
|
||||||
|
|
||||||
if [ ! -f nodes.txt ]; then echo "No nodes specified."; exit 2; fi
|
list_datasets()
|
||||||
|
|
||||||
read BR_HOST BR_PORT BR_ROOT BR_USER < nodes.txt
|
|
||||||
|
|
||||||
list_filesets()
|
|
||||||
{
|
{
|
||||||
zfs list | tail -n +2 | cut -d' ' -f1|grep ${BR_ROOT}
|
zfs list | tail -n +2 | cut -d' ' -f1|grep ${BR_ROOT}
|
||||||
}
|
}
|
||||||
@ -44,7 +40,7 @@ setup_aggregator()
|
|||||||
setup_mirror()
|
setup_mirror()
|
||||||
{
|
{
|
||||||
zfs allow -u ${BR_USER} send,snapshot,hold ${BR_ROOT}
|
zfs allow -u ${BR_USER} send,snapshot,hold ${BR_ROOT}
|
||||||
zfs allow -du ${BR_USER} \
|
zfs allow -u ${BR_USER} \
|
||||||
compression,mountpoint,receive,create,mount ${BR_ROOT}
|
compression,mountpoint,receive,create,mount ${BR_ROOT}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,31 +53,78 @@ create_snapshot()
|
|||||||
send_single_snapshot()
|
send_single_snapshot()
|
||||||
{
|
{
|
||||||
BR_NEW_SNAPSHOT=`get_latest_snapshot`
|
BR_NEW_SNAPSHOT=`get_latest_snapshot`
|
||||||
|
tail -n +2 nodes.txt > sendnodes.tmp
|
||||||
while read BR_REMOTE_ADDR BR_REMOTE_PORT BR_REMOTE_ROOT BR_REMOTE_USER; do
|
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}@${BR_NEW_SNAPSHOT}
|
||||||
|
else
|
||||||
zfs send -R ${BR_ROOT}@${BR_NEW_SNAPSHOT} |
|
zfs send -R ${BR_ROOT}@${BR_NEW_SNAPSHOT} |
|
||||||
ssh -i ~/.ssh/id_rsa -o port=${BR_REMOTE_PORT} \
|
ssh -i ~/.ssh/id_rsa -o port=${BR_REMOTE_PORT} \
|
||||||
${BR_REMOTE_USER}@${BR_REMOTE_ADDR} \
|
${BR_REMOTE_USER}@${BR_REMOTE_ADDR} \
|
||||||
zfs receive -dvu ${BR_REMOTE_ROOT}@${BR_NEW_SNAPSHOT}
|
zfs receive -dvu ${BR_REMOTE_ROOT}
|
||||||
done
|
fi
|
||||||
|
done < sendnodes.tmp
|
||||||
|
rm sendnodes.tmp
|
||||||
|
if [ $BR_TEST_MODE = "TRUE" ]; then
|
||||||
|
:
|
||||||
|
else
|
||||||
echo $BR_NEW_SNAPSHOT > "old-snapshot.txt"
|
echo $BR_NEW_SNAPSHOT > "old-snapshot.txt"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
send_incremental_snapshot()
|
send_incremental_snapshot()
|
||||||
{
|
{
|
||||||
BR_NEW_SNAPSHOT=`get_latest_snapshot`
|
BR_NEW_SNAPSHOT=`get_latest_snapshot`
|
||||||
while read BR_REMOTE_ADDR BR_REMOTE_PORT BR_REMOTE_ROOT BR_REMOTE_USER; do
|
echo Will send $BR_NEW_SNAPSHOT
|
||||||
zfs send -R -i `cat old-snapshot.txt` ${BR_ROOT}@${BR_NEW_SNAPSHOT} |
|
#while read BR_REMOTE_ADDR BR_REMOTE_PORT BR_REMOTE_ROOT BR_REMOTE_USER; do
|
||||||
ssh -i ~/.ssh/id_rsa -o port=${BR_REMOTE_PORT} \
|
# zfs send -R -i `cat old-snapshot.txt` ${BR_ROOT}@${BR_NEW_SNAPSHOT} |
|
||||||
${BR_REMOTE_USER}@${BR_REMOTE_ADDR} \
|
# ssh -i ~/.ssh/id_rsa -o port=${BR_REMOTE_PORT} \
|
||||||
zfs receive -dvu ${BR_REMOTE_ROOT}@${BR_NEW_SNAPSHOT}
|
# ${BR_REMOTE_USER}@${BR_REMOTE_ADDR} \
|
||||||
done
|
# zfs receive -dvu ${BR_REMOTE_ROOT}@${BR_NEW_SNAPSHOT}
|
||||||
|
#done
|
||||||
echo $BR_NEW_SNAPSHOT > "old-snapshot.txt"
|
echo $BR_NEW_SNAPSHOT > "old-snapshot.txt"
|
||||||
}
|
}
|
||||||
|
|
||||||
create_snapshot
|
|
||||||
|
|
||||||
|
################################### MAIN ####################################
|
||||||
|
|
||||||
|
### Options
|
||||||
|
set -- `getopt "tl:" "$@"` || {
|
||||||
|
echo "Usage: `basename $0` [-tl] [command]" 1>&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
BR_TEST_MODE=FALSE
|
||||||
|
while :; do
|
||||||
|
case "$1" in
|
||||||
|
-t)
|
||||||
|
BR_TEST_MODE=TRUE
|
||||||
|
echo Test mode.
|
||||||
|
;;
|
||||||
|
--) shift; break ;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
read BR_HOST BR_PORT BR_ROOT BR_USER < nodes.txt
|
||||||
|
|
||||||
|
if [ ! -f nodes.txt ]; then echo "No nodes specified."; exit 2; fi
|
||||||
|
|
||||||
|
### Command
|
||||||
|
case "$1" in
|
||||||
|
list) list_datasets ;;
|
||||||
|
create) create_snapshot ;;
|
||||||
|
setup-mirror) setup_mirror ;;
|
||||||
|
send)
|
||||||
if [ -f "old-snapshot.txt" ]; then
|
if [ -f "old-snapshot.txt" ]; then
|
||||||
send_incremental_snapshot
|
send_incremental_snapshot
|
||||||
else
|
else
|
||||||
send_single_snapshot
|
send_single_snapshot
|
||||||
fi
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user