mirror of
https://asciireactor.com/o4data/zfs-backup.git
synced 2024-11-22 05:55:05 +00:00
Updated to single data file.
This commit is contained in:
parent
1d093d39d6
commit
7e776ad42c
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,4 +1,3 @@
|
|||||||
datasets.txt
|
datasets.txt
|
||||||
rootzfs.txt
|
nodes.txt
|
||||||
hosts.txt
|
old-snapshot.txt
|
||||||
user.txt
|
|
||||||
|
65
backup.sh
65
backup.sh
@ -1,18 +1,11 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
## Data Format
|
### nodes.txt
|
||||||
|
# localhost 22 <this host's root zfs> <this host's user>
|
||||||
### user.txt
|
# <remote host 1 address> <host 1 port> <host 1 root zfs>
|
||||||
# <username>
|
# <remote host 2 address> <host 2 port> <host 2 root zfs>
|
||||||
|
|
||||||
### hosts.txt
|
|
||||||
# <host 1 address> <host 1 port> <host 1 root zfs>
|
|
||||||
# <host 2 address> <host 2 port> <host 2 root zfs>
|
|
||||||
# ...
|
# ...
|
||||||
|
|
||||||
### rootzfs.txt
|
|
||||||
# <root zfs>
|
|
||||||
|
|
||||||
### datasets.txt (Only required for aggregator setup.)
|
### datasets.txt (Only required for aggregator setup.)
|
||||||
# <dataset 1>
|
# <dataset 1>
|
||||||
# <dataset 1>/<dataset 1a>
|
# <dataset 1>/<dataset 1a>
|
||||||
@ -22,21 +15,19 @@
|
|||||||
# <dataset 3>
|
# <dataset 3>
|
||||||
# ...
|
# ...
|
||||||
|
|
||||||
if [ ! -f user.txt ]; then echo "No user specified."; exit 2; fi
|
if [ ! -f nodes.txt ]; then echo "No nodes specified."; exit 2; fi
|
||||||
if [ ! -f hosts.txt ]; then echo "No hosts specified."; exit 2; fi
|
|
||||||
if [ ! -f rootzfs.txt ]; then echo "No rootzfs specified."; exit 2; fi
|
|
||||||
|
|
||||||
BAKRNG_ROOT=`cat rootzfs.txt`
|
read BR_HOST BR_PORT BR_ROOT BR_USER < nodes.txt
|
||||||
|
|
||||||
list_filesets()
|
list_filesets()
|
||||||
{
|
{
|
||||||
zfs list | tail -n +2 | cut -d' ' -f1|grep ${BAKRNG_ROOT}
|
zfs list | tail -n +2 | cut -d' ' -f1|grep ${BR_ROOT}
|
||||||
}
|
}
|
||||||
|
|
||||||
get_latest_snapshot()
|
get_latest_snapshot()
|
||||||
{
|
{
|
||||||
zfs list -t snapshot |
|
zfs list -t snapshot |
|
||||||
grep ${BAKRNG_ROOT} |
|
grep ${BR_ROOT} |
|
||||||
tail -n1 |
|
tail -n1 |
|
||||||
cut -d'@' -f2 |
|
cut -d'@' -f2 |
|
||||||
cut -d' ' -f 1
|
cut -d' ' -f 1
|
||||||
@ -44,7 +35,7 @@ get_latest_snapshot()
|
|||||||
|
|
||||||
setup_aggregator()
|
setup_aggregator()
|
||||||
{
|
{
|
||||||
zfs allow -u `cat user.txt` send,snapshot,hold ${BAKRNG_ROOT}
|
zfs allow -u ${BR_USER} send,snapshot,hold ${BR_ROOT}
|
||||||
for dataset in `cat datasets.txt`; do
|
for dataset in `cat datasets.txt`; do
|
||||||
zfs create $dataset
|
zfs create $dataset
|
||||||
done
|
done
|
||||||
@ -52,43 +43,43 @@ setup_aggregator()
|
|||||||
|
|
||||||
setup_mirror()
|
setup_mirror()
|
||||||
{
|
{
|
||||||
zfs allow -u `cat user.txt` send,snapshot,hold ${BAKRNG_ROOT}
|
zfs allow -u ${BR_USER} send,snapshot,hold ${BR_ROOT}
|
||||||
zfs allow -du `cat user.txt` \
|
zfs allow -du ${BR_USER} \
|
||||||
compression,mountpoint,receive,create,mount ${BAKRNG_ROOT}
|
compression,mountpoint,receive,create,mount ${BR_ROOT}
|
||||||
}
|
}
|
||||||
|
|
||||||
create_snapshot()
|
create_snapshot()
|
||||||
{
|
{
|
||||||
id="`date -I`-`date +%s`"
|
id="`date -I`-`date +%s`"
|
||||||
zfs snapshot -r ${BAKRNG_ROOT}@${id}
|
zfs snapshot -r ${BR_ROOT}@${id}
|
||||||
}
|
}
|
||||||
|
|
||||||
send_single_snapshot()
|
send_single_snapshot()
|
||||||
{
|
{
|
||||||
BAKRNG_SEND_SNAPSHOT=`get_latest_snapshot`
|
BR_NEW_SNAPSHOT=`get_latest_snapshot`
|
||||||
while read BAKRNG_REMOTE_ADDR BAKRNG_REMOTE_PORT BAKRNG_REMOTE_ROOT; do
|
while read BR_REMOTE_ADDR BR_REMOTE_PORT BR_REMOTE_ROOT BR_REMOTE_USER; do
|
||||||
zfs send -R ${BAKRNG_ROOT}@${BAKRNG_SEND_SNAPSHOT} |
|
zfs send -R ${BR_ROOT}@${BR_NEW_SNAPSHOT} |
|
||||||
ssh -i ~/.ssh/id_rsa \
|
ssh -i ~/.ssh/id_rsa -o port=${BR_REMOTE_PORT} \
|
||||||
-o port=${BAKRNG_REMOTE_PORT} ${BAKRNG_REMOTE_ADDR} \
|
${BR_REMOTE_USER}@${BR_REMOTE_ADDR} \
|
||||||
zfs receive -dvu ${BAKRNG_REMOTE_ROOT}@${BAKRNG_SEND_SNAPSHOT}
|
zfs receive -dvu ${BR_REMOTE_ROOT}@${BR_NEW_SNAPSHOT}
|
||||||
done
|
done
|
||||||
echo $BAKRNG_SEND_SNAPSHOT > "last-snapshot.txt"
|
echo $BR_NEW_SNAPSHOT > "old-snapshot.txt"
|
||||||
}
|
}
|
||||||
|
|
||||||
send_incremental_snapshop()
|
send_incremental_snapshop()
|
||||||
{
|
{
|
||||||
BAKRNG_SEND_SNAPSHOT=`get_latest_snapshot`
|
BR_NEW_SNAPSHOT=`get_latest_snapshot`
|
||||||
while read BAKRNG_REMOTE_ADDR BAKRNG_REMOTE_PORT BAKRNG_REMOTE_ROOT; do
|
while read BR_REMOTE_ADDR BR_REMOTE_PORT BR_REMOTE_ROOT BR_REMOTE_USER; do
|
||||||
zfs send -R -i `cat last-snapshot.txt` \
|
zfs send -R -i `cat old-snapshot.txt` ${BR_ROOT}@${BR_NEW_SNAPSHOT} |
|
||||||
${BAKRNG_ROOT}@${BAKRNG_SEND_SNAPSHOT} | ssh -i ~/.ssh/id_rsa \
|
ssh -i ~/.ssh/id_rsa -o port=${BR_REMOTE_PORT} \
|
||||||
-o port=${BAKRNG_REMOTE_PORT} ${BAKRNG_REMOTE_ADDR} \
|
${BR_REMOTE_USER}@${BR_REMOTE_ADDR} \
|
||||||
zfs receive -dvu ${BAKRNG_REMOTE_ROOT}@${BAKRNG_SEND_SNAPSHOT}
|
zfs receive -dvu ${BR_REMOTE_ROOT}@${BR_NEW_SNAPSHOT}
|
||||||
done
|
done
|
||||||
echo $BAKRNG_SEND_SNAPSHOT > "last-snapshot.txt"
|
echo $BR_NEW_SNAPSHOT > "old-snapshot.txt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if [ -f "last-snapshot.txt" ]; then
|
if [ -f "old-snapshot.txt" ]; then
|
||||||
send_incremental_snapshop
|
send_incremental_snapshop
|
||||||
else
|
else
|
||||||
send_single_snapshot
|
send_single_snapshot
|
||||||
|
Loading…
Reference in New Issue
Block a user