mirror of
https://asciireactor.com/o4data/zfs-backup.git
synced 2024-11-22 04:35:06 +00:00
Fixed BR->BG.
This commit is contained in:
parent
81fc6126c6
commit
6234584bd1
94
backup.sh
94
backup.sh
@ -18,24 +18,24 @@ datasets_file="datasets.txt"
|
||||
|
||||
list_active_datasets()
|
||||
{
|
||||
zfs list | tail -n +2 | cut -d' ' -f1|grep ${BR_ROOT}
|
||||
zfs list | tail -n +2 | cut -d' ' -f1|grep ${BG_ROOT}
|
||||
}
|
||||
|
||||
read_datasets() {
|
||||
while read BR_REMOTE_ADDR BR_REMOTE_PORT BR_REMOTE_ROOT BR_REMOTE_USER; do
|
||||
case $BR_REMOTE_ADDR in
|
||||
while read BG_REMOTE_ADDR BG_REMOTE_PORT BG_REMOTE_ROOT BG_REMOTE_USER; do
|
||||
case $BG_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}
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
echo zfs send -R ${BG_ROOT}@${BG_NEW_SNAPSHOT}
|
||||
echo ssh -i ~/.ssh/id_rsa -o port=${BG_REMOTE_PORT} \
|
||||
${BG_REMOTE_USER}@${BG_REMOTE_ADDR} \
|
||||
zfs receive -vu ${BG_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}
|
||||
zfs send -R ${BG_ROOT}@${BG_NEW_SNAPSHOT} |
|
||||
ssh -i ~/.ssh/id_rsa -o port=${BG_REMOTE_PORT} \
|
||||
${BG_REMOTE_USER}@${BG_REMOTE_ADDR} \
|
||||
zfs receive -dvu ${BG_REMOTE_ROOT}
|
||||
fi
|
||||
done < ${datasets_file}
|
||||
}
|
||||
@ -45,14 +45,14 @@ read_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
|
||||
zfs create -p ${BG_ROOT}/$dataset
|
||||
done
|
||||
}
|
||||
|
||||
get_latest_snapshot()
|
||||
{
|
||||
zfs list -t snapshot |
|
||||
grep ${BR_ROOT} |
|
||||
grep ${BG_ROOT} |
|
||||
tail -n1 |
|
||||
cut -d'@' -f2 |
|
||||
cut -d' ' -f 1
|
||||
@ -60,68 +60,68 @@ get_latest_snapshot()
|
||||
|
||||
setup_aggregator()
|
||||
{
|
||||
zfs allow -u ${BR_USER} send,snapshot,hold ${BR_ROOT}
|
||||
zfs allow -u ${BG_USER} send,snapshot,hold ${BG_ROOT}
|
||||
create_datasets
|
||||
}
|
||||
|
||||
setup_mirror()
|
||||
{
|
||||
zfs create -p $BR_ROOT
|
||||
zfs create -p $BG_ROOT
|
||||
create_datasets
|
||||
zfs allow -u ${BR_USER} send,snapshot,hold ${BR_ROOT}
|
||||
zfs allow -u ${BR_USER} \
|
||||
compression,mountpoint,receive,create,mount ${BR_ROOT}
|
||||
zfs allow -u ${BG_USER} send,snapshot,hold ${BG_ROOT}
|
||||
zfs allow -u ${BG_USER} \
|
||||
compression,mountpoint,receive,create,mount ${BG_ROOT}
|
||||
}
|
||||
|
||||
create_snapshot()
|
||||
{
|
||||
id="`date -I`-`date +%s`"
|
||||
if [ $BR_TEST_MODE = "TRUE" ]; then
|
||||
echo zfs snapshot -r ${BR_ROOT}@${id}
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
echo zfs snapshot -r ${BG_ROOT}@${id}
|
||||
else
|
||||
zfs snapshot -r ${BR_ROOT}@${id}
|
||||
zfs snapshot -r ${BG_ROOT}@${id}
|
||||
fi
|
||||
}
|
||||
|
||||
send_single_snapshot()
|
||||
{
|
||||
BR_NEW_SNAPSHOT=`get_latest_snapshot`
|
||||
BG_NEW_SNAPSHOT=`get_latest_snapshot`
|
||||
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
|
||||
while read BG_REMOTE_ADDR BG_REMOTE_PORT BG_REMOTE_ROOT BG_REMOTE_USER; do
|
||||
case $BG_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 -dvu ${BR_REMOTE_ROOT}
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
echo zfs send -R ${BG_ROOT}@${BG_NEW_SNAPSHOT}
|
||||
echo ssh -i ~/.ssh/id_rsa -o port=${BG_REMOTE_PORT} \
|
||||
${BG_REMOTE_USER}@${BG_REMOTE_ADDR} \
|
||||
zfs receive -dvu ${BG_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}
|
||||
zfs send -R ${BG_ROOT}@${BG_NEW_SNAPSHOT} |
|
||||
ssh -i ~/.ssh/id_rsa -o port=${BG_REMOTE_PORT} \
|
||||
${BG_REMOTE_USER}@${BG_REMOTE_ADDR} \
|
||||
zfs receive -dvu ${BG_REMOTE_ROOT}
|
||||
fi
|
||||
done < sendnodes.tmp
|
||||
rm sendnodes.tmp
|
||||
if [ $BR_TEST_MODE = "TRUE" ]; then
|
||||
if [ $BG_TEST_MODE = "TRUE" ]; then
|
||||
:
|
||||
else
|
||||
echo $BR_NEW_SNAPSHOT > "old-snapshot.txt"
|
||||
echo $BG_NEW_SNAPSHOT > "old-snapshot.txt"
|
||||
fi
|
||||
}
|
||||
|
||||
send_incremental_snapshot()
|
||||
{
|
||||
BR_NEW_SNAPSHOT=`get_latest_snapshot`
|
||||
echo Will send $BR_NEW_SNAPSHOT
|
||||
#while read BR_REMOTE_ADDR BR_REMOTE_PORT BR_REMOTE_ROOT BR_REMOTE_USER; do
|
||||
# zfs send -R -i `cat old-snapshot.txt` ${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}@${BR_NEW_SNAPSHOT}
|
||||
BG_NEW_SNAPSHOT=`get_latest_snapshot`
|
||||
echo Will send $BG_NEW_SNAPSHOT
|
||||
#while read BG_REMOTE_ADDR BG_REMOTE_PORT BG_REMOTE_ROOT BG_REMOTE_USER; do
|
||||
# zfs send -R -i `cat old-snapshot.txt` ${BG_ROOT}@${BG_NEW_SNAPSHOT} |
|
||||
# ssh -i ~/.ssh/id_rsa -o port=${BG_REMOTE_PORT} \
|
||||
# ${BG_REMOTE_USER}@${BG_REMOTE_ADDR} \
|
||||
# zfs receive -dvu ${BG_REMOTE_ROOT}@${BG_NEW_SNAPSHOT}
|
||||
#done
|
||||
echo $BR_NEW_SNAPSHOT > "old-snapshot.txt"
|
||||
echo $BG_NEW_SNAPSHOT > "old-snapshot.txt"
|
||||
}
|
||||
|
||||
|
||||
@ -132,11 +132,11 @@ set -- `getopt "tl:" "$@"` || {
|
||||
echo "Usage: `basename $0` [-tl] [command]" 1>&2
|
||||
exit 1
|
||||
}
|
||||
BR_TEST_MODE=FALSE
|
||||
BG_TEST_MODE=FALSE
|
||||
while :; do
|
||||
case "$1" in
|
||||
-t)
|
||||
BR_TEST_MODE=TRUE
|
||||
BG_TEST_MODE=TRUE
|
||||
echo Test mode.
|
||||
;;
|
||||
--) shift; break ;;
|
||||
@ -144,7 +144,7 @@ while :; do
|
||||
shift
|
||||
done
|
||||
|
||||
read BR_HOST BR_PORT BR_ROOT BR_USER < ${nodes_file}
|
||||
read BG_HOST BG_PORT BG_ROOT BG_USER < ${nodes_file}
|
||||
|
||||
if [ ! -f ${nodes_file} ]; then echo "No nodes specified."; exit 2; fi
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user