dsnap-sync: make btrfs_quota usage an option
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
299
bin/dsnap-sync
299
bin/dsnap-sync
@@ -53,6 +53,7 @@ exec 3>$PIPE 4>$BTRFS_PIPE
|
|||||||
args=
|
args=
|
||||||
answer=no
|
answer=no
|
||||||
batch=0
|
batch=0
|
||||||
|
btrfs_quota=0
|
||||||
color=0
|
color=0
|
||||||
donotify=0
|
donotify=0
|
||||||
dryrun=0
|
dryrun=0
|
||||||
@@ -106,7 +107,7 @@ check_prerequisites () {
|
|||||||
if [ -z "$remote" ]; then
|
if [ -z "$remote" ]; then
|
||||||
$ssh which sh >/dev/null 2>&1 || \
|
$ssh which sh >/dev/null 2>&1 || \
|
||||||
{ printf "'remote shell' is not working!\n \
|
{ printf "'remote shell' is not working!\n \
|
||||||
Please correct your public authentication and try again.\n" && exit 1; }
|
Please correct your public authentication and try again.\n" && exit 1; }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -r "$SNAPPER_CONFIG" ]; then
|
if [ ! -r "$SNAPPER_CONFIG" ]; then
|
||||||
@@ -126,7 +127,7 @@ check_snapper_failed_ids () {
|
|||||||
# | awk ' /'host='"$remote"'/ {cnt++} END {print cnt}'"
|
# | awk ' /'host='"$remote"'/ {cnt++} END {print cnt}'"
|
||||||
|
|
||||||
if [ ${#snapper_failed_ids} -gt 0 ]; then
|
if [ ${#snapper_failed_ids} -gt 0 ]; then
|
||||||
if [ "$batch" ]; then
|
if [ "$batch" ]; then
|
||||||
answer="yes"
|
answer="yes"
|
||||||
else
|
else
|
||||||
printf "${MAGENTA}Found %s previous failed sync runs for '%s'${NO_COLOR}\n" "${snapper_failed_ids}" "$selected_config"
|
printf "${MAGENTA}Found %s previous failed sync runs for '%s'${NO_COLOR}\n" "${snapper_failed_ids}" "$selected_config"
|
||||||
@@ -179,10 +180,10 @@ create_snapshot () {
|
|||||||
snapper_source_snapshot=$SUBVOLUME/.snapshots/$snapper_source_id/snapshot
|
snapper_source_snapshot=$SUBVOLUME/.snapshots/$snapper_source_id/snapshot
|
||||||
snapper_source_info=$SUBVOLUME/.snapshots/$snapper_source_id/info.xml
|
snapper_source_info=$SUBVOLUME/.snapshots/$snapper_source_id/info.xml
|
||||||
|
|
||||||
btrfs quota enable $snapper_source_snapshot
|
#btrfs quota enable $snapper_source_snapshot
|
||||||
sync
|
sync
|
||||||
|
|
||||||
if [ $verbose -ge 3 ]; then
|
if [ $verbose -ge 3 ]; then
|
||||||
printf "${MAGENTA}Snapper source snapshot ${GREEN}'%s'${MAGENTA} created${NO_COLOR}\n" "$snapper_source_id"
|
printf "${MAGENTA}Snapper source snapshot ${GREEN}'%s'${MAGENTA} created${NO_COLOR}\n" "$snapper_source_id"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@@ -308,7 +309,7 @@ get_snapper_target_backupdir () {
|
|||||||
if [ $verbose -ge 2 ]; then
|
if [ $verbose -ge 2 ]; then
|
||||||
# WIP: we need to adapt existing target config SUBVOLUME to reflect the new backupdir
|
# WIP: we need to adapt existing target config SUBVOLUME to reflect the new backupdir
|
||||||
printf "${RED}TODO: ${MAGENTA}Reset backupdir ${GREEN}'%s'${MAGENTA} as requested per commandline.${NO_COLOR}\n" \
|
printf "${RED}TODO: ${MAGENTA}Reset backupdir ${GREEN}'%s'${MAGENTA} as requested per commandline.${NO_COLOR}\n" \
|
||||||
"$backupdir"
|
"$backupdir"
|
||||||
printf "${RED}TODO: ${NO_COLOR}Need to adapt ${GREEN}SUBVOLUME${NO_COLOR} for existing ${GREEN}target-config${NO_COLOR}, to reflect the new backupdir.\n"
|
printf "${RED}TODO: ${NO_COLOR}Need to adapt ${GREEN}SUBVOLUME${NO_COLOR} for existing ${GREEN}target-config${NO_COLOR}, to reflect the new backupdir.\n"
|
||||||
fi
|
fi
|
||||||
die "Changing the backupdir for an already existing target-config is not supported yet.\n"
|
die "Changing the backupdir for an already existing target-config is not supported yet.\n"
|
||||||
@@ -355,8 +356,8 @@ get_disk_infos () {
|
|||||||
| grep -v $exclude_uuid \
|
| grep -v $exclude_uuid \
|
||||||
| awk '{print $1}')
|
| awk '{print $1}')
|
||||||
disk_targets=$(eval $ssh findmnt --noheadings --nofsroot --types btrfs --output UUID,TARGET --list \
|
disk_targets=$(eval $ssh findmnt --noheadings --nofsroot --types btrfs --output UUID,TARGET --list \
|
||||||
| grep -v $exclude_uuid \
|
| grep -v $exclude_uuid \
|
||||||
| awk '{print $2}')
|
| awk '{print $2}')
|
||||||
fs_options=$(eval $ssh findmnt --noheadings --nofsroot --types btrfs --output UUID,OPTIONS --list \
|
fs_options=$(eval $ssh findmnt --noheadings --nofsroot --types btrfs --output UUID,OPTIONS --list \
|
||||||
| grep -v $exclude_uuid \
|
| grep -v $exclude_uuid \
|
||||||
| awk '{print $2}')
|
| awk '{print $2}')
|
||||||
@@ -388,17 +389,17 @@ get_disk_infos () {
|
|||||||
else
|
else
|
||||||
disk_uuid_match="$i"
|
disk_uuid_match="$i"
|
||||||
fi
|
fi
|
||||||
disk_uuid_match_count=$(($disk_uuid_match_count+1))
|
disk_uuid_match_count=$(($disk_uuid_match_count+1))
|
||||||
fi
|
fi
|
||||||
eval "disk_uuid_$i='$disk_uuid'"
|
eval "disk_uuid_$i='$disk_uuid'"
|
||||||
disk_count=$(($disk_count+1))
|
disk_count=$(($disk_count+1))
|
||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
done
|
done
|
||||||
i=0
|
i=0
|
||||||
for disk_target in $disk_targets; do
|
for disk_target in $disk_targets; do
|
||||||
if [ "$disk_target" = "$target_cmdline" ]; then
|
if [ "$disk_target" = "$target_cmdline" ]; then
|
||||||
disk_target_match="$i"
|
disk_target_match="$i"
|
||||||
disk_target_match_count=$(($disk_target_match_count+1))
|
disk_target_match_count=$(($disk_target_match_count+1))
|
||||||
fi
|
fi
|
||||||
eval "disk_target_$i='$disk_target'"
|
eval "disk_target_$i='$disk_target'"
|
||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
@@ -408,7 +409,7 @@ get_disk_infos () {
|
|||||||
subvolid=$(eval echo \$fs_option | sed -e 's/.*subvolid=\([0-9]*\).*/\1/')
|
subvolid=$(eval echo \$fs_option | sed -e 's/.*subvolid=\([0-9]*\).*/\1/')
|
||||||
if [ "$subvolid" = "$subvolid_cmdline" ]; then
|
if [ "$subvolid" = "$subvolid_cmdline" ]; then
|
||||||
disk_subvolid_match="$i"
|
disk_subvolid_match="$i"
|
||||||
disk_subvolid_match_count=$(($disk_subvolid_match_count+1))
|
disk_subvolid_match_count=$(($disk_subvolid_match_count+1))
|
||||||
fi
|
fi
|
||||||
eval "fs_options_$i='$fs_option'"
|
eval "fs_options_$i='$fs_option'"
|
||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
@@ -445,7 +446,7 @@ get_snapper_config_type () {
|
|||||||
case $key in
|
case $key in
|
||||||
CONFIG_TYPE)
|
CONFIG_TYPE)
|
||||||
snapper_config_type=$(eval echo $value | sed -e 's/\"\(.*\)\"/\1/')
|
snapper_config_type=$(eval echo $value | sed -e 's/\"\(.*\)\"/\1/')
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
CHILD_CONFIG)
|
CHILD_CONFIG)
|
||||||
snapper_target_config=$(eval echo $value | sed -e 's/\"\(.*\)\"/\1/')
|
snapper_target_config=$(eval echo $value | sed -e 's/\"\(.*\)\"/\1/')
|
||||||
@@ -457,8 +458,8 @@ get_snapper_config_type () {
|
|||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
# value is not relevant
|
# value is not relevant
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done < $SNAPPER_CONFIG_DIR/$snapper_config
|
done < $SNAPPER_CONFIG_DIR/$snapper_config
|
||||||
|
|
||||||
@@ -593,7 +594,7 @@ get_snapper_sync_id () {
|
|||||||
[ ${#remote} -gt 0 ] && run_ssh=$ssh
|
[ ${#remote} -gt 0 ] && run_ssh=$ssh
|
||||||
|
|
||||||
cmd="snapper --config "$snapper_config" list --type single \
|
cmd="snapper --config "$snapper_config" list --type single \
|
||||||
| awk -F '|' '\$1 == "$snapper_sync_id" {print \$1}' "
|
| awk -F '|' '\$1 == "$snapper_sync_id" {print \$1}' "
|
||||||
ret=$(eval $run_ssh snapper --config "$snapper_config" list --type single \
|
ret=$(eval $run_ssh snapper --config "$snapper_config" list --type single \
|
||||||
| awk -F '|' '$1 == '"$snapper_sync_id"' {gsub(" ",""); print $1}')
|
| awk -F '|' '$1 == '"$snapper_sync_id"' {gsub(" ",""); print $1}')
|
||||||
printf "ret: '%s'\n" $ret
|
printf "ret: '%s'\n" $ret
|
||||||
@@ -615,7 +616,7 @@ notify () {
|
|||||||
# estimation: batch calls should just log
|
# estimation: batch calls should just log
|
||||||
if [ $donotify -gt 0 ]; then
|
if [ $donotify -gt 0 ]; then
|
||||||
for u in $(users | sed 's/ /\n/' | sort -u); do
|
for u in $(users | sed 's/ /\n/' | sort -u); do
|
||||||
sudo -u $u DISPLAY=:0 \
|
sudo -u $u DISPLAY=:0 \
|
||||||
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(sudo -u $u id -u)/bus \
|
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(sudo -u $u id -u)/bus \
|
||||||
notify-send -a $progname "$progname: $1" "$2" --icon="dialog-$3"
|
notify-send -a $progname "$progname: $1" "$2" --icon="dialog-$3"
|
||||||
done
|
done
|
||||||
@@ -639,31 +640,31 @@ parse_params () {
|
|||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
key="$1"
|
key="$1"
|
||||||
case $key in
|
case $key in
|
||||||
-h | --help | \-\? | --usage)
|
-h | --help | \-\? | --usage)
|
||||||
# Call usage() function.
|
# Call usage() function.
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
-a|--automount)
|
-a|--automount)
|
||||||
automount_path="$2"
|
automount_path="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-b|--backupdir)
|
-b|--backupdir)
|
||||||
backupdir_cmdline="$2"
|
backupdir_cmdline="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-c|--config)
|
-c|--config)
|
||||||
if [ ${#selected_config} -gt 0 ]; then
|
if [ ${#selected_config} -gt 0 ]; then
|
||||||
selected_configs="${selected_configs} ${2}"
|
selected_configs="${selected_configs} ${2}"
|
||||||
else
|
else
|
||||||
selected_configs="$2"
|
selected_configs="$2"
|
||||||
fi
|
fi
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--config-postfix)
|
--config-postfix)
|
||||||
snapper_config_postfix="$2"
|
snapper_config_postfix="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--description-finished)
|
--description-finished)
|
||||||
shift
|
shift
|
||||||
snap_description_finished="${*}"
|
snap_description_finished="${*}"
|
||||||
snap_description_finished="${snap_description_finished%% -*}"
|
snap_description_finished="${snap_description_finished%% -*}"
|
||||||
@@ -673,7 +674,7 @@ parse_params () {
|
|||||||
set -- $params
|
set -- $params
|
||||||
shift $count
|
shift $count
|
||||||
;;
|
;;
|
||||||
--description-running)
|
--description-running)
|
||||||
shift
|
shift
|
||||||
snap_description_running=${*}
|
snap_description_running=${*}
|
||||||
snap_description_running="${snap_description_running%% -*}"
|
snap_description_running="${snap_description_running%% -*}"
|
||||||
@@ -683,7 +684,7 @@ parse_params () {
|
|||||||
set -- $params
|
set -- $params
|
||||||
shift $count
|
shift $count
|
||||||
;;
|
;;
|
||||||
-d|--description|--description-synced)
|
-d|--description|--description-synced)
|
||||||
shift
|
shift
|
||||||
snap_description_synced="${*}"
|
snap_description_synced="${*}"
|
||||||
snap_description_synced="${snap_description_synced%% -*}"
|
snap_description_synced="${snap_description_synced%% -*}"
|
||||||
@@ -697,12 +698,12 @@ parse_params () {
|
|||||||
dryrun=1
|
dryrun=1
|
||||||
shift 1
|
shift 1
|
||||||
;;
|
;;
|
||||||
-i|--interactive)
|
-i|--interactive)
|
||||||
interactive=1
|
interactive=1
|
||||||
donotify=1
|
donotify=1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-n|--noconfirm|--batch)
|
-n|--noconfirm|--batch)
|
||||||
batch=1
|
batch=1
|
||||||
interactive=0
|
interactive=0
|
||||||
do_pv_cmd=0
|
do_pv_cmd=0
|
||||||
@@ -721,7 +722,7 @@ parse_params () {
|
|||||||
do_pv_cmd=0
|
do_pv_cmd=0
|
||||||
shift 1
|
shift 1
|
||||||
;;
|
;;
|
||||||
-p|--port)
|
-p|--port)
|
||||||
port=$2
|
port=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
@@ -729,47 +730,51 @@ parse_params () {
|
|||||||
remote=$2
|
remote=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-s|--subvolid|--SUBVOLID)
|
-s|--subvolid|--SUBVOLID)
|
||||||
subvolid_cmdline="$2"
|
subvolid_cmdline="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-t|--target|--TARGET)
|
-t|--target|--TARGET)
|
||||||
target_cmdline="$2"
|
target_cmdline="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-u|--uuid|--UUID)
|
-u|--uuid|--UUID)
|
||||||
uuid_cmdline="$2"
|
uuid_cmdline="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-v|--verbose)
|
--use-btrfs-quota)
|
||||||
|
btrfs_quota=1
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
-v|--verbose)
|
||||||
verbose=$(($verbose + 1))
|
verbose=$(($verbose + 1))
|
||||||
shift 1
|
shift 1
|
||||||
;;
|
;;
|
||||||
--version)
|
--version)
|
||||||
printf "%s v%s\n" "$progname" "$version"
|
printf "%s v%s\n" "$progname" "$version"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
--automount=*)
|
--automount=*)
|
||||||
automount_path=${1#*=}
|
automount_path=${1#*=}
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--backupdir=*)
|
--backupdir=*)
|
||||||
backupdir_cmdline=${1#*=}
|
backupdir_cmdline=${1#*=}
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--config=*)
|
--config=*)
|
||||||
if [ ${#selected_config} -gt 0 ]; then
|
if [ ${#selected_config} -gt 0 ]; then
|
||||||
selected_config="${selected_config} ${1#*=}"
|
selected_config="${selected_config} ${1#*=}"
|
||||||
else
|
else
|
||||||
selected_config="${1#*=}"
|
selected_config="${1#*=}"
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--config-postfix=*)
|
--config-postfix=*)
|
||||||
snapper_config_postfix="${1#*=}"
|
snapper_config_postfix="${1#*=}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--color=*)
|
--color=*)
|
||||||
case ${1#*=} in
|
case ${1#*=} in
|
||||||
yes | Yes | True | true)
|
yes | Yes | True | true)
|
||||||
color=1;
|
color=1;
|
||||||
@@ -777,9 +782,9 @@ parse_params () {
|
|||||||
*)
|
*)
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--description-finished=*)
|
--description-finished=*)
|
||||||
snap_description_finished="${*#*=}"
|
snap_description_finished="${*#*=}"
|
||||||
snap_description_finished="${snap_description_finished%% -*}"
|
snap_description_finished="${snap_description_finished%% -*}"
|
||||||
params_new=${*#*=}
|
params_new=${*#*=}
|
||||||
@@ -790,7 +795,7 @@ parse_params () {
|
|||||||
set -- $params_new
|
set -- $params_new
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
--description-running=*)
|
--description-running=*)
|
||||||
snap_description_running="${*#*=}"
|
snap_description_running="${*#*=}"
|
||||||
snap_description_running="${snap_description_running%% -*}"
|
snap_description_running="${snap_description_running%% -*}"
|
||||||
params_new=${*#*=}
|
params_new=${*#*=}
|
||||||
@@ -802,7 +807,7 @@ parse_params () {
|
|||||||
set -- $params_new
|
set -- $params_new
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
-d=*|--description=*|--description-synced=*)
|
-d=*|--description=*|--description-synced=*)
|
||||||
snap_description_synced="${*#*=}"
|
snap_description_synced="${*#*=}"
|
||||||
snap_description_synced="${snap_description_synced%% -*}"
|
snap_description_synced="${snap_description_synced%% -*}"
|
||||||
params_new=${*#*=}
|
params_new=${*#*=}
|
||||||
@@ -815,39 +820,39 @@ parse_params () {
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
--port=*)
|
--port=*)
|
||||||
port=${1#*=}
|
port=${1#*=}
|
||||||
shift
|
shift
|
||||||
;;
|
|
||||||
--remote=*)
|
|
||||||
remote=${1#*=}
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--subvolid=*|--SUBVOLID=*)
|
|
||||||
subvolid_cmdline=${1#*=}
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--target=*|--TARGET=*)
|
|
||||||
target_cmdline=${1#*=}
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--uuid=*|--UUID=*)
|
|
||||||
uuid_cmdline=${1#*=}
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--v=* | --verbose=*)
|
|
||||||
verbose=${1#*=}
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--) # End of all options
|
|
||||||
shift
|
|
||||||
break
|
|
||||||
;;
|
;;
|
||||||
-*)
|
--remote=*)
|
||||||
printf "WARN: Unknown option (ignored): $1" >&2
|
remote=${1#*=}
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--subvolid=*|--SUBVOLID=*)
|
||||||
|
subvolid_cmdline=${1#*=}
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--target=*|--TARGET=*)
|
||||||
|
target_cmdline=${1#*=}
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--uuid=*|--UUID=*)
|
||||||
|
uuid_cmdline=${1#*=}
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--v=* | --verbose=*)
|
||||||
|
verbose=${1#*=}
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--) # End of all options
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
printf "WARN: Unknown option (ignored): $1" >&2
|
||||||
die "Unknown option"
|
die "Unknown option"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
printf "Unknown option: %s\nRun '%s -h' for valid options.\n" $key $progname
|
printf "Unknown option: %s\nRun '%s -h' for valid options.\n" $key $progname
|
||||||
die "Unknown option"
|
die "Unknown option"
|
||||||
;;
|
;;
|
||||||
@@ -873,12 +878,12 @@ parse_params () {
|
|||||||
else
|
else
|
||||||
ssh="ssh $remote"
|
ssh="ssh $remote"
|
||||||
if [ ! -z "$port" ]; then
|
if [ ! -z "$port" ]; then
|
||||||
ssh="$ssh -p $port"
|
ssh="$ssh -p $port"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$color" ]; then
|
if [ "$color" ]; then
|
||||||
# ascii color
|
# ascii color
|
||||||
BLUE='\033[0;34m'
|
BLUE='\033[0;34m'
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
MAGENTA='\033[0;35m'
|
MAGENTA='\033[0;35m'
|
||||||
@@ -909,17 +914,17 @@ parse_params () {
|
|||||||
if [ $dryrun -eq 1 ]; then snap_sync_options="${snap_sync_options} dry-run=true"; fi
|
if [ $dryrun -eq 1 ]; then snap_sync_options="${snap_sync_options} dry-run=true"; fi
|
||||||
if [ $donotify -eq 1 ]; then snap_sync_options="${snap_sync_options} donotify=true"; fi
|
if [ $donotify -eq 1 ]; then snap_sync_options="${snap_sync_options} donotify=true"; fi
|
||||||
if [ $color -eq 1 ]; then snap_sync_options="${snap_sync_options} color=true"; fi
|
if [ $color -eq 1 ]; then snap_sync_options="${snap_sync_options} color=true"; fi
|
||||||
|
if [ $btrfs_quota -eq 1 ]; then snap_sync_options="${snap_sync_options} use-btrfs-quota=true"; fi
|
||||||
if [ $batch -eq 1 ]; then
|
if [ $batch -eq 1 ]; then
|
||||||
snap_sync_options="${snap_sync_options} batch=true do_pv_cmd=$do_pv_cmd"
|
snap_sync_options="${snap_sync_options} batch=true do_pv_cmd=$do_pv_cmd"
|
||||||
else
|
else
|
||||||
snap_sync_options="${snap_sync_options} interactive=true do_pv_cmd=$do_pv_cmd"
|
snap_sync_options="${snap_sync_options} interactive=true do_pv_cmd=$do_pv_cmd"
|
||||||
fi
|
fi
|
||||||
#if [ "$interactive" -eq 1 ]; then snap_sync_options="${snap_sync_options} interactive=true"; fi
|
#if [ "$interactive" -eq 1 ]; then snap_sync_options="${snap_sync_options} interactive=true"; fi
|
||||||
printf "Options: '%s'\n\n" "${snap_sync_options}"
|
printf "Options: '%s'\n\n" "${snap_sync_options}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
quote_args () {
|
quote_args () {
|
||||||
# quote command in ssh call to prevent remote side from expanding any arguments
|
# quote command in ssh call to prevent remote side from expanding any arguments
|
||||||
# using dash's buildin printf
|
# using dash's buildin printf
|
||||||
@@ -1005,8 +1010,8 @@ run_config_preparation () {
|
|||||||
snapper_source_sync_snapshot=$value/.snapshots/$snapper_source_sync_id/snapshot
|
snapper_source_sync_snapshot=$value/.snapshots/$snapper_source_sync_id/snapshot
|
||||||
fi
|
fi
|
||||||
if [ $verbose -ge 2 ]; then
|
if [ $verbose -ge 2 ]; then
|
||||||
printf "${MAGENTA}Last synced ${GREEN}source snapshot${MAGENTA} for snapper config ${GREEN}'%s'${MAGENTA} is ${GREEN}'%s'${MAGENTA} ...${NO_COLOR}\n" \
|
printf "${MAGENTA}Last synced ${GREEN}source snapshot${MAGENTA} for snapper config ${GREEN}'%s'${MAGENTA} is ${GREEN}'%s'${MAGENTA} ...${NO_COLOR}\n" \
|
||||||
"$selected_config" "$snapper_sync_id"
|
"$selected_config" "$snapper_sync_id"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# verfiy target
|
# verfiy target
|
||||||
@@ -1017,19 +1022,19 @@ run_config_preparation () {
|
|||||||
if [ $snapper_target_sync_id -eq 0 ]; then
|
if [ $snapper_target_sync_id -eq 0 ]; then
|
||||||
if [ $verbose -ge 2 ]; then
|
if [ $verbose -ge 2 ]; then
|
||||||
if [ $remote ]; then
|
if [ $remote ]; then
|
||||||
printf "${MAGENTA}No target shapshot available for snapper config ${GREEN}'%s'${MAGENTA} on '%s'...${NO_COLOR}\n" \
|
printf "${MAGENTA}No target shapshot available for snapper config ${GREEN}'%s'${MAGENTA} on '%s'...${NO_COLOR}\n" \
|
||||||
"$selected_config" "$remote"
|
"$selected_config" "$remote"
|
||||||
else
|
else
|
||||||
printf "${MAGENTA}No target shapshot available for snapper config ${GREEN}'%s'${MAGENTA}...${NO_COLOR}\n" \
|
printf "${MAGENTA}No target shapshot available for snapper config ${GREEN}'%s'${MAGENTA}...${NO_COLOR}\n" \
|
||||||
"$selected_config"
|
"$selected_config"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
backup_root=$selected_target/$backupdir/$snapper_target_config
|
backup_root=$selected_target/$backupdir/$snapper_target_config
|
||||||
#snapper_target_sync_id=$snapper_source_sync_id
|
#snapper_target_sync_id=$snapper_source_sync_id
|
||||||
else
|
else
|
||||||
# get backupdir from snapper target
|
# get backupdir from snapper target
|
||||||
get_snapper_target_backupdir $backupdir
|
get_snapper_target_backupdir $backupdir
|
||||||
|
|
||||||
# set target sync_snapshot path
|
# set target sync_snapshot path
|
||||||
get_snapper_config_value "remote=$remote" \
|
get_snapper_config_value "remote=$remote" \
|
||||||
@@ -1052,7 +1057,7 @@ run_config_preparation () {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# save values in config specific pseudo arrays
|
# save values in config specific pseudo arrays
|
||||||
eval "snapper_source_config_$i='$selected_config'"
|
eval "snapper_source_config_$i='$selected_config'"
|
||||||
eval "snapper_target_config_$i='$snapper_target_config'"
|
eval "snapper_target_config_$i='$snapper_target_config'"
|
||||||
eval "snapper_config_type_$i='$snapper_config_type'"
|
eval "snapper_config_type_$i='$snapper_config_type'"
|
||||||
@@ -1095,16 +1100,16 @@ run_backup () {
|
|||||||
SNAP_SYNC_EXCLUDE=no
|
SNAP_SYNC_EXCLUDE=no
|
||||||
|
|
||||||
if [ -f "/etc/snapper/configs/$selected_config" ]; then
|
if [ -f "/etc/snapper/configs/$selected_config" ]; then
|
||||||
. /etc/snapper/configs/$selected_config
|
. /etc/snapper/configs/$selected_config
|
||||||
else
|
else
|
||||||
die "Selected snapper configuration '$selected_config' does not exist."
|
die "Selected snapper configuration '$selected_config' does not exist."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cont_backup=$(eval echo \$snapper_activate_$i)
|
cont_backup=$(eval echo \$snapper_activate_$i)
|
||||||
if [ "$cont_backup" = "no" ] || [ "$SNAP_SYNC_EXCLUDE" = "yes" ]; then
|
if [ "$cont_backup" = "no" ] || [ "$SNAP_SYNC_EXCLUDE" = "yes" ]; then
|
||||||
if [ $donotify -gt 0 ]; then
|
if [ $donotify -gt 0 ]; then
|
||||||
notify_info "Backup in progress" "NOTE: Skipping '$selected_config' configuration."
|
notify_info "Backup in progress" "NOTE: Skipping '$selected_config' configuration."
|
||||||
fi
|
fi
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -1113,8 +1118,8 @@ run_backup () {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# retrieve config specific infos from pseudo Arrays
|
# retrieve config specific infos from pseudo Arrays
|
||||||
snapper_source_config=$(eval echo \$snapper_source_config_$i)
|
snapper_source_config=$(eval echo \$snapper_source_config_$i)
|
||||||
snapper_target_config=$(eval echo \$snapper_target_config_$i)
|
snapper_target_config=$(eval echo \$snapper_target_config_$i)
|
||||||
snapper_config_type=$(eval echo \$snapper_config_type_$i)
|
snapper_config_type=$(eval echo \$snapper_config_type_$i)
|
||||||
snapper_source_sync_id=$(eval echo \$snapper_source_sync_id_$i)
|
snapper_source_sync_id=$(eval echo \$snapper_source_sync_id_$i)
|
||||||
snapper_source_sync_snapshot=$(eval echo \$snapper_source_sync_snapshot_$i)
|
snapper_source_sync_snapshot=$(eval echo \$snapper_source_sync_snapshot_$i)
|
||||||
@@ -1132,8 +1137,8 @@ run_backup () {
|
|||||||
fi
|
fi
|
||||||
# check for last common snapshot
|
# check for last common snapshot
|
||||||
snapper_source_id=$snapper_source_sync_id
|
snapper_source_id=$snapper_source_sync_id
|
||||||
snapper_source_snapshot=$SUBVOLUME/.snapshots/$snapper_source_sync_id/snapshot
|
snapper_source_snapshot=$SUBVOLUME/.snapshots/$snapper_source_sync_id/snapshot
|
||||||
snapper_source_info=$SUBVOLUME/.snapshots/$snapper_source_sync_id/info.xml
|
snapper_source_info=$SUBVOLUME/.snapshots/$snapper_source_sync_id/info.xml
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
if [ $verbose -ge 3 ]; then
|
if [ $verbose -ge 3 ]; then
|
||||||
@@ -1165,37 +1170,43 @@ run_backup () {
|
|||||||
"$snapper_source_id" "$snapper_source_snapshot"
|
"$snapper_source_id" "$snapper_source_snapshot"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# qgroup for given path, exclude ancestrals
|
if [ $btrfs_quota -eq 1 ]; then
|
||||||
# qgroup identifiers conform to level/id where level 0 is reserved to the qgroups associated with subvolumes
|
# qgroup for given path, exclude ancestrals
|
||||||
snapper_source_snapshot_size=$(eval btrfs qgroup show -f --raw $snapper_source_snapshot 2>/dev/null \
|
# qgroup identifiers conform to level/id where level 0 is reserved to the qgroups associated with subvolumes
|
||||||
| awk 'FNR>2 {print $2}')
|
snapper_source_snapshot_size=$(eval btrfs qgroup show -f --raw $snapper_source_snapshot 2>/dev/null \
|
||||||
if [ $verbose -ge 3 ]; then
|
| awk 'FNR>2 {print $2}')
|
||||||
printf "${MAGENTA}BTRFS qgroup show result: ${GREEN}'%s'\b${NO_COLOR}'%s'\n" \
|
if [ $verbose -ge 3 ]; then
|
||||||
"$?" "$snapper_source_snapshot_size"
|
printf "${MAGENTA}BTRFS qgroup show result: ${GREEN}'%s'\b${NO_COLOR}'%s'\n" \
|
||||||
fi
|
"$?" "$snapper_source_snapshot_size"
|
||||||
#if [ $? -eq 1 ]; then
|
fi
|
||||||
|
#if [ $? -eq 1 ]; then
|
||||||
# subvolume is not configured for quota, (temporary?) enable that
|
# subvolume is not configured for quota, (temporary?) enable that
|
||||||
#btrfs_quota_tmp=1
|
#btrfs_quota_tmp=1
|
||||||
#btrfs quota enable $snapper_source_snapshot 2>/dev/null
|
#btrfs quota enable $snapper_source_snapshot 2>/dev/null
|
||||||
#btrfs quota rescan -w $snapper_source_snapshot 2>/dev/null
|
#btrfs quota rescan -w $snapper_source_snapshot 2>/dev/null
|
||||||
#fi
|
#fi
|
||||||
|
|
||||||
# need to substitue btrfs 'x.yyGiB' suffix, since pv will need 'xG'
|
# need to substitue btrfs 'x.yyGiB' suffix, since pv will need 'xG'
|
||||||
if [ $snapper_source_snapshot_size -ge 1073741824 ]; then
|
if [ $snapper_source_snapshot_size -ge 1073741824 ]; then
|
||||||
snapper_source_snapshot_size=$(eval btrfs qgroup show -f --gbytes $snapper_source_snapshot 2>/dev/null \
|
snapper_source_snapshot_size=$(eval btrfs qgroup show -f --gbytes $snapper_source_snapshot 2>/dev/null \
|
||||||
| awk 'FNR>2 { gsub(/.[0-9][0-9]GiB/,"G"); print $2}')
|
| awk 'FNR>2 { gsub(/.[0-9][0-9]GiB/,"G"); print $2}')
|
||||||
|
fi
|
||||||
|
if [ $verbose -ge 2 ]; then
|
||||||
|
printf "${MAGENTA}BTRFS quota size for ${GREEN}source snapshot${MAGENTA}: id=${GREEN}'%s'${MAGENTA}, size=${GREEN}'%s'${NO_COLOR} ...\n" \
|
||||||
|
"$snapper_source_id" "$snapper_source_snapshot_size"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# should we disable quota usage again?
|
||||||
|
#if [ $btrfs_quota_tmp -eq 1 ]; then btrfs quota disable $snapper_source_snapshot; fi
|
||||||
|
else
|
||||||
|
snapper_source_snapshot_size=$(du --sum $snapper_source_snapshot 2>/dev/null \
|
||||||
|
| awk -F ' ' '{print $1}')
|
||||||
|
snapper_source_snapshot_size=$(($snapper_source_snapshot_size / 1024 / 1024))G
|
||||||
|
if [ $verbose -ge 2 ]; then
|
||||||
|
printf "${MAGENTA}BTRFS subvolume size for ${GREEN}source snapshot${MAGENTA}: id=${GREEN}'%s'${MAGENTA}, size=${GREEN}'%s'${NO_COLOR} ...\n" \
|
||||||
|
"$snapper_source_id" "$snapper_source_snapshot_size"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
if [ $verbose -ge 2 ]; then
|
|
||||||
printf "${MAGENTA}BTRFS quota size for ${GREEN}source snapshot${MAGENTA}: id=${GREEN}'%s'${MAGENTA}, size=${GREEN}'%s'${NO_COLOR} ...\n" \
|
|
||||||
"$snapper_source_id" "$snapper_source_snapshot_size"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# should we disable quota usage again?
|
|
||||||
#if [ $btrfs_quota_tmp -eq 1 ]; then btrfs quota disable $snapper_source_snapshot; fi
|
|
||||||
|
|
||||||
#snapper_source_snapshot_size=$(du --sum $snapper_source_snapshot 2>/dev/null \
|
|
||||||
# | awk -F ' ' '{print $1}')
|
|
||||||
#snapper_source_snapshot_size=$(($snapper_source_snapshot_size / 1024 / 1024))G
|
|
||||||
|
|
||||||
# settings for interactive progress status
|
# settings for interactive progress status
|
||||||
if [ $do_pv_cmd -eq 1 ]; then
|
if [ $do_pv_cmd -eq 1 ]; then
|
||||||
@@ -1236,9 +1247,9 @@ run_backup () {
|
|||||||
printf "New ${GREEN}source${NO_COLOR} snapshot id: ${GREEN}'%s'${NO_COLOR} (path: ${GREEN}'%s'${NO_COLOR})\n" \
|
printf "New ${GREEN}source${NO_COLOR} snapshot id: ${GREEN}'%s'${NO_COLOR} (path: ${GREEN}'%s'${NO_COLOR})\n" \
|
||||||
"$snapper_source_id" "$snapper_source_snapshot"
|
"$snapper_source_id" "$snapper_source_snapshot"
|
||||||
printf "Last synced ${GREEN}target${NO_COLOR} snapshot id: ${GREEN}'%s'${NO_COLOR} (path: ${GREEN}'%s'${NO_COLOR})\n" \
|
printf "Last synced ${GREEN}target${NO_COLOR} snapshot id: ${GREEN}'%s'${NO_COLOR} (path: ${GREEN}'%s'${NO_COLOR})\n" \
|
||||||
"$snapper_target_sync_id" "$snapper_target_sync_snapshot"
|
"$snapper_target_sync_id" "$snapper_target_sync_snapshot"
|
||||||
printf "New ${GREEN}target${NO_COLOR} snapshot id: ${GREEN}'%s'${NO_COLOR} (path: ${GREEN}'%s'${NO_COLOR})\n" \
|
printf "New ${GREEN}target${NO_COLOR} snapshot id: ${GREEN}'%s'${NO_COLOR} (path: ${GREEN}'%s'${NO_COLOR})\n" \
|
||||||
"$snapper_target_id" "$snapper_target_snapshot/snapshot"
|
"$snapper_target_id" "$snapper_target_snapshot/snapshot"
|
||||||
fi
|
fi
|
||||||
# verify that source snapshot-id corresponds to a matching target snapshot-id
|
# verify that source snapshot-id corresponds to a matching target snapshot-id
|
||||||
if [ $snapper_target_sync_id -ne $snapper_source_sync_id ]; then
|
if [ $snapper_target_sync_id -ne $snapper_source_sync_id ]; then
|
||||||
@@ -1506,7 +1517,8 @@ run_finalize () {
|
|||||||
if [ $verbose -ge 3 ]; then
|
if [ $verbose -ge 3 ]; then
|
||||||
printf "${MAGENTA}Tagging snapper metadata${NO_COLOR} for snapper id ${GREEN}'%s'${NO_COLOR} on source for configuration ${GREEN}'%s'${NO_COLOR} ...\n" \
|
printf "${MAGENTA}Tagging snapper metadata${NO_COLOR} for snapper id ${GREEN}'%s'${NO_COLOR} on source for configuration ${GREEN}'%s'${NO_COLOR} ...\n" \
|
||||||
"$snapper_source_id" "$selected_config"
|
"$snapper_source_id" "$selected_config"
|
||||||
printf "calling: '%s'\n" "$(eval $cmd)"
|
# printf "calling: '%s'\n" "$(eval $cmd)"
|
||||||
|
printf "calling: '%s'\n" "$cmd"
|
||||||
fi
|
fi
|
||||||
ret=$(eval "$cmd")
|
ret=$(eval "$cmd")
|
||||||
if [ $verbose -ge 3 ]; then
|
if [ $verbose -ge 3 ]; then
|
||||||
@@ -1522,7 +1534,7 @@ run_finalize () {
|
|||||||
if [ $verbose -ge 3 ]; then
|
if [ $verbose -ge 3 ]; then
|
||||||
printf "${MAGENTA}Tagging snapper metadata${NO_COLOR} for snapper sync id ${GREEN}'%s'${NO_COLOR} on source for configuration ${GREEN}'%s'${NO_COLOR} ...\n" \
|
printf "${MAGENTA}Tagging snapper metadata${NO_COLOR} for snapper sync id ${GREEN}'%s'${NO_COLOR} on source for configuration ${GREEN}'%s'${NO_COLOR} ...\n" \
|
||||||
"$snapper_source_sync_id" "$selected_config"
|
"$snapper_source_sync_id" "$selected_config"
|
||||||
printf "calling: '%s'\n" "$(eval $cmd)"
|
printf "calling: '%s'\n" "$cmd"
|
||||||
fi
|
fi
|
||||||
ret=$(eval "$cmd")
|
ret=$(eval "$cmd")
|
||||||
snapper_source_sync_snapshot=$SUBVOLUME/.snapshots/$snapper_source_sync_id/snapshot
|
snapper_source_sync_snapshot=$SUBVOLUME/.snapshots/$snapper_source_sync_id/snapshot
|
||||||
@@ -1540,7 +1552,7 @@ run_finalize () {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $verbose -ge 1 ]; then
|
if [ $verbose -ge 1 ]; then
|
||||||
printf "Backup complete: id=${GREEN}'%s'${NOCOLOR}, config=${GREEN}'%s'${NOCOLOR}\n" \
|
printf "Backup complete: id=${GREEN}'%s'${NO_COLOR}, config=${GREEN}'%s'${NO_COLOR}\n" \
|
||||||
"$snapper_source_id" "$selected_config"
|
"$snapper_source_id" "$selected_config"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -1714,6 +1726,7 @@ Usage: $progname [options]
|
|||||||
Options:
|
Options:
|
||||||
-a, --automount <path> start automount for given path to get a valid target mountpoint.
|
-a, --automount <path> start automount for given path to get a valid target mountpoint.
|
||||||
-b, --backupdir <prefix> backupdir is a relative path that will be appended to target backup-root
|
-b, --backupdir <prefix> backupdir is a relative path that will be appended to target backup-root
|
||||||
|
--use-btrfs-quota use btrfs-quota to calculate snapshot size
|
||||||
-d, --description <desc> Change the snapper description. Default: "latest incremental backup"
|
-d, --description <desc> Change the snapper description. Default: "latest incremental backup"
|
||||||
--label-finished <desc> snapper description tagging successful jobs. Default: "dsnap-sync backup"
|
--label-finished <desc> snapper description tagging successful jobs. Default: "dsnap-sync backup"
|
||||||
--label-running <desc> snapper description tagging active jobs. Default: "dsnap-sync in progress"
|
--label-running <desc> snapper description tagging active jobs. Default: "dsnap-sync in progress"
|
||||||
@@ -1991,11 +2004,11 @@ verify_snapper_structure () {
|
|||||||
# create the non existing remote BTRFS subvolume for given snapshot
|
# create the non existing remote BTRFS subvolume for given snapshot
|
||||||
#cmd="$ssh btrfs subvolume create $backup_root/$snapper_snapshot 1>/dev/null"
|
#cmd="$ssh btrfs subvolume create $backup_root/$snapper_snapshot 1>/dev/null"
|
||||||
#$(eval $cmd) || \
|
#$(eval $cmd) || \
|
||||||
# die "Creation of BTRFS subvolume (snapshot): %s:%s failed.\n" \
|
# die "Creation of BTRFS subvolume (snapshot): %s:%s failed.\n" \
|
||||||
# "$remote_host" "$backup_root" "$remote_host"
|
# "$remote_host" "$backup_root" "$remote_host"
|
||||||
# cmd="$ssh chmod 0700 $backup_root 1>/dev/null"
|
# cmd="$ssh chmod 0700 $backup_root 1>/dev/null"
|
||||||
# $(eval $cmd) || \
|
# $(eval $cmd) || \
|
||||||
# die "Changing the directory mode for '$backup_root' on '$remote_host'."
|
# die "Changing the directory mode for '$backup_root' on '$remote_host'."
|
||||||
else
|
else
|
||||||
printf "dryrun: Would create new snapper configuration from template %s ...\n" "$snapper_subvolume_template"
|
printf "dryrun: Would create new snapper configuration from template %s ...\n" "$snapper_subvolume_template"
|
||||||
printf "dryrun: Would create new snapper subvolume '%s' ...\n" "$backup_root/$snapper_snapshot"
|
printf "dryrun: Would create new snapper subvolume '%s' ...\n" "$backup_root/$snapper_snapshot"
|
||||||
|
|||||||
Reference in New Issue
Block a user