mirror of
https://asciireactor.com/o4data/zfs-backup.git
synced 2024-11-22 01:05:05 +00:00
Initialize with first draft.
This commit is contained in:
commit
64e49bcf4d
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
datasets.txt
|
||||||
|
rootzfs.txt
|
||||||
|
hosts.txt
|
||||||
|
user.txt
|
73
backup.sh
Executable file
73
backup.sh
Executable file
@ -0,0 +1,73 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
BAKRNG_ROOT=`cat rootzfs.txt`
|
||||||
|
|
||||||
|
if [ ! -f user.txt ]; then echo "No user 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
|
||||||
|
|
||||||
|
list_filesets()
|
||||||
|
{
|
||||||
|
zfs list | tail -n +2 | cut -d' ' -f1|grep ${BAKRNG_ROOT}
|
||||||
|
}
|
||||||
|
|
||||||
|
get_latest_snapshot()
|
||||||
|
{
|
||||||
|
zfs list -t snapshot |
|
||||||
|
grep ${BAKRNG_ROOT} |
|
||||||
|
tail -n1 |
|
||||||
|
cut -d'@' -f2 |
|
||||||
|
cut -d' ' -f 1
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_aggregator()
|
||||||
|
{
|
||||||
|
zfs allow -u `cat user.txt` send,snapshot,hold ${BAKRNG_ROOT}
|
||||||
|
for dataset in `cat datasets.txt`; do
|
||||||
|
zfs create $dataset
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_mirror()
|
||||||
|
{
|
||||||
|
zfs allow -u `cat user.txt` send,snapshot,hold ${BAKRNG_ROOT}
|
||||||
|
zfs allow -du `cat user.txt` \
|
||||||
|
compression,mountpoint,receive,create,mount ${BAKRNG_ROOT}
|
||||||
|
}
|
||||||
|
|
||||||
|
create_snapshot()
|
||||||
|
{
|
||||||
|
id="`date -I`-`date +%s`"
|
||||||
|
echo zfs snapshot -r ${BAKRNG_ROOT}@${id}
|
||||||
|
}
|
||||||
|
|
||||||
|
send_single_snapshot()
|
||||||
|
{
|
||||||
|
BAKRNG_SEND_SNAPSHOT=`get_latest_snapshot`
|
||||||
|
while read BAKRNG_REMOTE_ADDR BAKRNG_REMOTE_PORT BAKRNG_REMOTE_ROOT; do
|
||||||
|
echo "zfs send -R ${BAKRNG_ROOT}@${BAKRNG_SEND_SNAPSHOT} |
|
||||||
|
ssh -i ~/.ssh/id_rsa \
|
||||||
|
-o port=${BAKRNG_REMOTE_PORT} ${BAKRNG_REMOTE_ADDR} \
|
||||||
|
zfs receive -dvu ${BAKRNG_REMOTE_ROOT}@${BAKRNG_SEND_SNAPSHOT}"
|
||||||
|
done
|
||||||
|
# echo $BAKRNG_SEND_SNAPSHOT > "last-snapshot.txt"
|
||||||
|
}
|
||||||
|
|
||||||
|
send_incremental_snapshop()
|
||||||
|
{
|
||||||
|
BAKRNG_SEND_SNAPSHOT=`get_latest_snapshot`
|
||||||
|
while read BAKRNG_REMOTE_ADDR BAKRNG_REMOTE_PORT BAKRNG_REMOTE_ROOT; do
|
||||||
|
echo "zfs send -R -i `cat last-snapshot.txt` \
|
||||||
|
${BAKRNG_ROOT}@${BAKRNG_SEND_SNAPSHOT} | ssh -i ~/.ssh/id_rsa \
|
||||||
|
-o port=${BAKRNG_REMOTE_PORT} ${BAKRNG_REMOTE_ADDR} \
|
||||||
|
zfs receive -dvu ${BAKRNG_REMOTE_ROOT}@${BAKRNG_SEND_SNAPSHOT}"
|
||||||
|
done
|
||||||
|
# echo $BAKRNG_SEND_SNAPSHOT > "last-snapshot.txt"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if [ -f "last-snapshot.txt" ]; then
|
||||||
|
send_incremental_snapshop
|
||||||
|
else
|
||||||
|
send_single_snapshot
|
||||||
|
fi
|
Loading…
Reference in New Issue
Block a user