Number of generations to keep. Default: 0 (none).
-On a *btrfs* target file systems (see `target` variable), this script can
-generate generations using *btrfs snapshots*: the script creates a new snapshot
+On a suitable target file systems (see `target` variable), this script can
+generate generations using snapshots: the script creates a new snapshot
named with the timestamp for each generation inside of the system directory
inside of the target directory.
+Supported file systems are:
+
+ * *btrfs*:
+ All generations are btrfs subvolumes and named after the date and time.
+ * *ZFS*:
+ All generations are ZFS filesystems. Latest generation is named `current`,
+ olders are links to the ZFS snapshot directories.
+
+The latest snapshot is always reachable using a symlink named `latest`
+inside the system directory.
+
### [default_]job_pre_exec
Optional script to execute before `rsync` starts. Default: none.
"btrfs")
btrfs subvolume create "$volume" >/dev/null || return 1
;;
+ "zfs")
+ zfs create "$(echo "$volume" | cut -c2-)" || return 1
+ ;;
*)
echo "CreateSubvolume: Incompatible FS type \"$fs\" on \"$dir\"!"
return 9
local snapshot="$3"
local dir
local fs
+ local link_name
dir=$(dirname "source")
fs=$(GetFS "$source")
"btrfs")
btrfs subvolume snapshot "$source" "$snapshot" >/dev/null || return 1
;;
+ "zfs")
+ zfs snapshot "$snapshot" || return 1
+ link_name="$(echo "$snapshot" | cut -d@ -f2-)"
+ ln -s \
+ "$volume/.zfs/snapshot/$link_name" \
+ "$(dirname "$volume")/$link_name"
+ ;;
*)
echo "CloneSubvolume: Incompatible FS type \"$fs\" on \"$source\"!"
return 9
"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
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
sys_target="$sys_target/$(date +%Y%m%d-%H%M%S)"
snapshot="$sys_target"
;;
+ "zfs")
+ # On ZFS, the last generation is always named "current"
+ [ -e "$sys_target/current" ] \
+ && last="$sys_target/current" \
+ || last=""
+ snapshot="$(echo "$sys_target/current" | cut -c2-)@$(date +%Y%m%d-%H%M%S)"
+ sys_target="$sys_target/current"
+ ;;
*)
echo "Initialize_Last_SysTarget_Snapshot: Incompatible FS type \"$fs\" on \"$sys_target\"!"
return 1