mirror of
https://asciireactor.com/o4data/zfs-backup.git
synced 2024-11-22 10:25:06 +00:00
Compare commits
6 Commits
e090fcf21d
...
a5600ff6e6
Author | SHA1 | Date | |
---|---|---|---|
a5600ff6e6 | |||
e3a1897e9c | |||
2573fb8847 | |||
679b6fc1a8 | |||
f7a43122d1 | |||
88258df653 |
45
backup.sh
45
backup.sh
@ -44,7 +44,8 @@ debug()
|
|||||||
run_send_recv()
|
run_send_recv()
|
||||||
{
|
{
|
||||||
ssh_cmd="ssh $SSH_SEND_OPTS -o port=$port $user@$addr"
|
ssh_cmd="ssh $SSH_SEND_OPTS -o port=$port $user@$addr"
|
||||||
if [ $ZB_TEST_MODE = "TRUE" ]; then
|
pv_cmd="pv -qL ${speed:-$DEFAULT_SPEED}"
|
||||||
|
if [ "$ZB_TEST_MODE" = "TRUE" ]; then
|
||||||
echo "$send_cmd | $pv_cmd | $ssh_cmd $recv_cmd"
|
echo "$send_cmd | $pv_cmd | $ssh_cmd $recv_cmd"
|
||||||
else
|
else
|
||||||
$send_cmd | $pv_cmd | $ssh_cmd $recv_cmd
|
$send_cmd | $pv_cmd | $ssh_cmd $recv_cmd
|
||||||
@ -53,7 +54,7 @@ run_send_recv()
|
|||||||
|
|
||||||
run_snapshot()
|
run_snapshot()
|
||||||
{
|
{
|
||||||
if [ $ZB_TEST_MODE = "TRUE" ]; then
|
if [ "$ZB_TEST_MODE" = "TRUE" ]; then
|
||||||
echo zfs snapshot $ZFS_SNAPSHOT_OPTS $dset@$snapid
|
echo zfs snapshot $ZFS_SNAPSHOT_OPTS $dset@$snapid
|
||||||
else
|
else
|
||||||
zfs snapshot $ZFS_SNAPSHOT_OPTS $dset@$snapid
|
zfs snapshot $ZFS_SNAPSHOT_OPTS $dset@$snapid
|
||||||
@ -62,7 +63,7 @@ run_snapshot()
|
|||||||
|
|
||||||
run_allow()
|
run_allow()
|
||||||
{
|
{
|
||||||
if [ $ZB_TEST_MODE = "TRUE" ]; then
|
if [ "$ZB_TEST_MODE" = "TRUE" ]; then
|
||||||
echo zfs allow -u $LOCAL_USER $ORIGIN_PERMS $dset
|
echo zfs allow -u $LOCAL_USER $ORIGIN_PERMS $dset
|
||||||
else
|
else
|
||||||
zfs allow -u $LOCAL_USER $ORIGIN_PERMS $dset
|
zfs allow -u $LOCAL_USER $ORIGIN_PERMS $dset
|
||||||
@ -72,7 +73,7 @@ run_allow()
|
|||||||
run_remote()
|
run_remote()
|
||||||
{
|
{
|
||||||
ssh_cmd="ssh $SSH_SEND_OPTS -o port=$port $user@$addr"
|
ssh_cmd="ssh $SSH_SEND_OPTS -o port=$port $user@$addr"
|
||||||
if [ $ZB_TEST_MODE = "TRUE" ]; then
|
if [ "$ZB_TEST_MODE" = "TRUE" ]; then
|
||||||
echo "\`$ssh_cmd $remote_cmd\`"
|
echo "\`$ssh_cmd $remote_cmd\`"
|
||||||
else
|
else
|
||||||
$ssh_cmd $remote_cmd
|
$ssh_cmd $remote_cmd
|
||||||
@ -80,7 +81,7 @@ run_remote()
|
|||||||
}
|
}
|
||||||
|
|
||||||
set_compression() {
|
set_compression() {
|
||||||
case $SEND_COMPRESSED in
|
case "$SEND_COMPRESSED" in
|
||||||
[tTyY]*) ZFS_SEND_OPTS="$ZFS_SEND_OPTS -c"
|
[tTyY]*) ZFS_SEND_OPTS="$ZFS_SEND_OPTS -c"
|
||||||
debug "Enabled send as compressed datasets." ;;
|
debug "Enabled send as compressed datasets." ;;
|
||||||
esac
|
esac
|
||||||
@ -89,14 +90,14 @@ set_compression() {
|
|||||||
populate_datasets()
|
populate_datasets()
|
||||||
{
|
{
|
||||||
while read dset dataset_options; do
|
while read dset dataset_options; do
|
||||||
case $dset in
|
case "$dset" in
|
||||||
\#*) continue;;
|
\#*) continue;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
snapshot_dataset="yes"
|
snapshot_dataset="yes"
|
||||||
send_dataset="yes"
|
send_dataset="yes"
|
||||||
for option in $dataset_options; do
|
for option in $dataset_options; do
|
||||||
case $option in
|
case "$option" in
|
||||||
"nosnap"* )
|
"nosnap"* )
|
||||||
snapshot_dataset=""
|
snapshot_dataset=""
|
||||||
;;
|
;;
|
||||||
@ -132,8 +133,8 @@ list_datasets()
|
|||||||
list_remote_datasets() {
|
list_remote_datasets() {
|
||||||
while read addr user port zroot speed; do
|
while read addr user port zroot speed; do
|
||||||
echo "=== $user@$addr $zroot ==="
|
echo "=== $user@$addr $zroot ==="
|
||||||
if [ $zroot ]; then
|
if [ "$zroot" ]; then
|
||||||
case $zroot in
|
case "$zroot" in
|
||||||
*"/") ;;
|
*"/") ;;
|
||||||
*) zroot="$zroot/" ;;
|
*) zroot="$zroot/" ;;
|
||||||
esac
|
esac
|
||||||
@ -156,7 +157,7 @@ get_latest_snapshot()
|
|||||||
get_latest_remote_snapshot()
|
get_latest_remote_snapshot()
|
||||||
{
|
{
|
||||||
if [ $zroot ]; then
|
if [ $zroot ]; then
|
||||||
case $zroot in
|
case "$zroot" in
|
||||||
*"/") ;;
|
*"/") ;;
|
||||||
*) zroot="$zroot/" ;;
|
*) zroot="$zroot/" ;;
|
||||||
esac
|
esac
|
||||||
@ -164,7 +165,6 @@ get_latest_remote_snapshot()
|
|||||||
list_cmd="zfs list -t snapshot $zroot$dset"
|
list_cmd="zfs list -t snapshot $zroot$dset"
|
||||||
remote_cmd="$list_cmd|tail -n1|cut -d'@' -f2|cut -d' ' -f 1"
|
remote_cmd="$list_cmd|tail -n1|cut -d'@' -f2|cut -d' ' -f 1"
|
||||||
run_remote
|
run_remote
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zfs_allow_origin()
|
zfs_allow_origin()
|
||||||
@ -179,8 +179,8 @@ zfs_allow_mirrors()
|
|||||||
{
|
{
|
||||||
while read addr user port zroot speed; do
|
while read addr user port zroot speed; do
|
||||||
echo "=== $user@$addr $zroot ==="
|
echo "=== $user@$addr $zroot ==="
|
||||||
if [ $zroot ]; then
|
if [ "$zroot" ]; then
|
||||||
case $zroot in
|
case "$zroot" in
|
||||||
*"/") ;;
|
*"/") ;;
|
||||||
*) zroot="$zroot/" ;;
|
*) zroot="$zroot/" ;;
|
||||||
esac
|
esac
|
||||||
@ -200,7 +200,7 @@ create_snapshots()
|
|||||||
snapid="`date -I`-`date +%s`-$LOCAL_TZ"
|
snapid="`date -I`-`date +%s`-$LOCAL_TZ"
|
||||||
for dset in $SNAPSHOT_DATASETS; do
|
for dset in $SNAPSHOT_DATASETS; do
|
||||||
run_snapshot
|
run_snapshot
|
||||||
debug Created snapshot $dset@$snapid.
|
debug "Created snapshot $dset@$snapid."
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,8 +208,8 @@ send_latest()
|
|||||||
{
|
{
|
||||||
while read addr user port zroot speed; do
|
while read addr user port zroot speed; do
|
||||||
echo "=== $user@$addr $zroot ==="
|
echo "=== $user@$addr $zroot ==="
|
||||||
if [ $zroot ]; then
|
if [ "$zroot" ]; then
|
||||||
case $zroot in
|
case "$zroot" in
|
||||||
*"/") ;;
|
*"/") ;;
|
||||||
*) zroot="$zroot/" ;;
|
*) zroot="$zroot/" ;;
|
||||||
esac
|
esac
|
||||||
@ -218,9 +218,8 @@ send_latest()
|
|||||||
rset=`echo $dset|cut -d: -f2`
|
rset=`echo $dset|cut -d: -f2`
|
||||||
dset=`echo $dset|cut -d: -f1`
|
dset=`echo $dset|cut -d: -f1`
|
||||||
debug "Processing $dset (remote $rset)."
|
debug "Processing $dset (remote $rset)."
|
||||||
snap1=`get_latest_snapshot $dset`
|
snap1=`get_latest_snapshot`
|
||||||
send_cmd="zfs send $ZFS_SEND_OPTS $dset@$snap1"
|
send_cmd="zfs send $ZFS_SEND_OPTS $dset@$snap1"
|
||||||
pv_cmd="pv -qL ${speed:-$DEFAULT_SPEED}"
|
|
||||||
recv_cmd="zfs recv $ZFS_RECV_OPTS $zroot$rset"
|
recv_cmd="zfs recv $ZFS_RECV_OPTS $zroot$rset"
|
||||||
run_send_recv
|
run_send_recv
|
||||||
done
|
done
|
||||||
@ -231,8 +230,8 @@ send_increment()
|
|||||||
{
|
{
|
||||||
while read addr user port zroot speed; do
|
while read addr user port zroot speed; do
|
||||||
echo "=== $user@$addr $zroot ==="
|
echo "=== $user@$addr $zroot ==="
|
||||||
if [ $zroot ]; then
|
if [ "$zroot" ]; then
|
||||||
case $zroot in
|
case "$zroot" in
|
||||||
*"/") ;;
|
*"/") ;;
|
||||||
*) zroot="$zroot/" ;;
|
*) zroot="$zroot/" ;;
|
||||||
esac
|
esac
|
||||||
@ -243,7 +242,6 @@ send_increment()
|
|||||||
snap1=`get_latest_snapshot`
|
snap1=`get_latest_snapshot`
|
||||||
snap0=`get_latest_remote_snapshot`
|
snap0=`get_latest_remote_snapshot`
|
||||||
send_cmd="zfs send $ZFS_SEND_OPTS -i $dset@$snap0 $dset@$snap1"
|
send_cmd="zfs send $ZFS_SEND_OPTS -i $dset@$snap0 $dset@$snap1"
|
||||||
pv_cmd="pv -qL ${speed:-$DEFAULT_SPEED}"
|
|
||||||
recv_cmd="zfs recv $ZFS_RECV_OPTS $zroot$rset"
|
recv_cmd="zfs recv $ZFS_RECV_OPTS $zroot$rset"
|
||||||
run_send_recv
|
run_send_recv
|
||||||
done
|
done
|
||||||
@ -253,12 +251,11 @@ send_increment()
|
|||||||
|
|
||||||
################################### MAIN ####################################
|
################################### MAIN ####################################
|
||||||
|
|
||||||
### Options
|
|
||||||
set -- `getopt "tvl:" "$@"` || {
|
set -- `getopt "tvl:" "$@"` || {
|
||||||
echo "Usage: `basename $0` [-tvl] [command]" 1>&2
|
echo "Usage: `basename $0` [-tvl] [command]" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
ZB_TEST_MODE=FALSE
|
|
||||||
while :; do
|
while :; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-t)
|
-t)
|
||||||
@ -270,7 +267,7 @@ while :; do
|
|||||||
ZFS_SEND_OPTS="$ZFS_SEND_OPTS -v"
|
ZFS_SEND_OPTS="$ZFS_SEND_OPTS -v"
|
||||||
# Current on by default.
|
# Current on by default.
|
||||||
# ZFS_RECV_OPTS="$ZFS_RECV_OPTS -v"
|
# ZFS_RECV_OPTS="$ZFS_RECV_OPTS -v"
|
||||||
debug "Enabled terbose mode."
|
debug "Enabled verbose mode."
|
||||||
;;
|
;;
|
||||||
--) shift; break ;;
|
--) shift; break ;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user