+RenameSubvolume() {
+ local source="$1"
+ local target="$2"
+ local fs
+
+ fs=$(GetFS "$source")
+ case "$fs" in
+ "btrfs")
+ mv "$source" "$target" || return 1
+ ;;
+ "zfs")
+ zfs rename \
+ "$(echo "$source" | cut -c2-)" \
+ "$(echo "$target" | cut -c2-)" \
+ || return 1
+ ;;
+ *)
+ echo "RenameSubvolume: Incompatible FS type \"$fs\" on \"$source\"!"
+ return 9
+ esac
+ return 0
+}
+
+DeleteSubvolume() {
+ local volume="$1"
+ local fs
+ local id
+ local snapshot
+
+ fs=$(GetFS "$volume")
+ case "$fs" in
+ "btrfs")
+ btrfs subvolume delete "$volume" >/dev/null || return 1
+ ;;
+ "zfs")
+ id="$(basename "$volume")"
+ if [ -h "$volume" ]; then
+ snapshot="$(dirname "$volume")/current@$id"
+ else
+ snapshot="$volume"
+ fi
+ zfs destroy -r "$(echo "$snapshot" | cut -c2-)" >/dev/null || return 1
+ [ -h "$volume" ] && rm "$volume"
+ ;;
+ *)
+ echo "DeleteSubvolume: Incompatible FS type \"$fs\" on \"$volume\"!"
+ return 9
+ esac
+ return 0
+}
+
+Initialize_Last_SysTarget_Snapshot() {
+ sys_target="$1"
+ unset last
+ unset snapshot
+
+ fs=$(GetFS "$sys_target")
+ case "$fs" in
+ "btrfs")
+ # Search directory of last generation, if any
+ last=$(ls -1d "$sys_target"/[0-9]* 2>/dev/null | sort -r | head -n1)
+ if [ -n "$last" ]; then
+ if [ ! -d "$last" ]; then
+ echo "Last snapshot \"$last\" seems not to be a directory!? \"$system\" skipped!"
+ echo
+ return 1
+ fi
+ fi
+ sys_target="$sys_target/$(date +%Y%m%d-%H%M%S)"
+ snapshot="$sys_target"
+ ;;
+ "zfs")
+ # On ZFS, the last generation is always named "current"
+ if [ -e "$sys_target/current" ]; then
+ last="$sys_target/current"
+ if [ "$(uname)" = "Linux" ]; then
+ date=$(LC_ALL=C stat "$1" | grep "^Modify: " \
+ | cut -d':' -f2- | cut -d. -f1)
+ else
+ date=$(LC_ALL=C stat -f "%Sc" "$1")
+ fi
+ date=$(echo "$date" | sed -e's/^ //g' -e 's/[-:]//g' -e 's/ /-/g')
+
+ else
+ last=""
+ date="$(date +%Y%m%d-%H%M%S)"
+ fi
+ snapshot="$(echo "$sys_target/current" | cut -c2-)@$date"
+ sys_target="$sys_target/current"
+ ;;
+ *)
+ echo "Initialize_Last_SysTarget_Snapshot: Incompatible FS type \"$fs\" on \"$sys_target\"!"
+ return 1
+ esac
+ return 0
+}
+
+# Search configuration file (last one is used as default!)
+for conf in \
+ "/usr/local/etc/backup-script.conf" \
+ "/etc/backup-script.conf" \
+ "${conf_d}/backup-script.conf" \
+ "/usr/local/etc/backup-script.conf" \
+; do
+ [ -r "$conf" ] && break
+done
+
+# Read in configuration file
+config_info="Configuration file is \"$conf\""
+if [ -r "$conf" ]; then
+ source "$conf"
+else
+ config_info="${config_info} (not readable, using defaults)"
+fi
+config_info="${config_info},\nusing \"$conf_d\" as configuration directory."
+
+while [ $# -gt 0 ]; do
+ case "$1" in
+ "-n"|"--dry-run")
+ DRYRUN=1; shift
+ ;;
+ "-p"|"--progress")
+ VERBOSE=1; shift
+ ;;
+ "-"*)
+ Usage
+ ;;
+ *)
+ break
+ esac
+done