]> arthur.barton.de Git - backup-script.git/blobdiff - bin/backup-script
Add support for generations on ZFS
[backup-script.git] / bin / backup-script
index 37cbc53bd9d2da49d6b3ed9b01cf00b876665f91..5df6c6710bd58d1a803c31262785f6ca8690bad2 100755 (executable)
@@ -122,6 +122,9 @@ CreateSubvolume() {
          "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
@@ -135,6 +138,7 @@ CloneSubvolume() {
        local snapshot="$3"
        local dir
        local fs
+       local link_name
 
        dir=$(dirname "source")
        fs=$(GetFS "$source")
@@ -142,6 +146,13 @@ CloneSubvolume() {
          "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
@@ -159,6 +170,12 @@ RenameSubvolume() {
          "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
@@ -169,12 +186,24 @@ RenameSubvolume() {
 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
@@ -202,6 +231,14 @@ Initialize_Last_SysTarget_Snapshot() {
                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