]> arthur.barton.de Git - ax-linux.git/commitdiff
btrfs-mksnapshot: Correctly detect volume "base name"
authorAlexander Barton <alex@barton.de>
Sat, 19 Apr 2014 12:50:02 +0000 (14:50 +0200)
committerAlexander Barton <alex@barton.de>
Sat, 19 Apr 2014 12:50:02 +0000 (14:50 +0200)
btrfs/mksnapshot/btrfs-mksnapshot

index a3fb8adca435426ca722adc9f6fa490335f19056..d100b451b04d01b1e9101dbedbb99566364f0555 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/bash -e
 #
 # btrfs-mksnapshot -- Make snapshots of btrfs filesystems
-# Copyright (c)2013 Alexander Barton (alex@barton.de)
+# Copyright (c)2013-2014 Alexander Barton (alex@barton.de)
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -74,8 +74,12 @@ if [ -z "$VOLUME_NAME" ]; then
        echo "$NAME: Failed to detect btrfs subvolume name for \"$VOLUME_PATH\"!"
        exit 1
 fi
+BASE_VOLUME_NAME=`echo "$VOLUME_NAME" | cut -d'-' -f1`
 
-[ -z "$DRY_RUN" ] || echo "VOLUME_NAME=$VOLUME_NAME"
+if [ -n "$DRY_RUN" ]; then
+       echo "VOLUME_NAME=$VOLUME_NAME"
+       echo "BASE_VOLUME_NAME=$BASE_VOLUME_NAME"
+fi
 
 # Detect mount point of the whole btrfs filesystem
 FS_MOUNT_PATH="/media/$FS_NAME"
@@ -96,14 +100,14 @@ i=1
 date=`date +%Y%m%d`
 while true; do
        id="$date-$i"
-       [ -e "$FS_MOUNT_PATH/$VOLUME_NAME-$id" ] || break
+       [ -e "$FS_MOUNT_PATH/$BASE_VOLUME_NAME-$id" ] || break
        if [ -n "$ONLY_ONE_PER_DAY" ]; then
-               echo "Daily snapshot of \"$VOLUME_PATH\" (\"$VOLUME_NAME\") in btrfs \"$FS_NAME\" already exists."
+               echo "Snapshot \"$BASE_VOLUME_NAME-$id\" of \"$VOLUME_PATH\" (\"$VOLUME_NAME\") in btrfs \"$FS_NAME\" already exists."
                exit 0
        fi
        i=`expr $i + 1`
 done
-NEW_VOLUME_NAME="`echo $VOLUME_NAME | cut -d'-' -f1`-$id"
+NEW_VOLUME_NAME="$BASE_VOLUME_NAME-$id"
 
 [ -z "$DRY_RUN" ] || echo "NEW_VOLUME_NAME=$NEW_VOLUME_NAME"
 
@@ -114,4 +118,5 @@ set -x
 
 cd "$FS_MOUNT_PATH"
 btrfs subvolume snapshot "$VOLUME_NAME" "$NEW_VOLUME_NAME"
-find . -maxdepth 1 -name "$VOLUME_NAME"'*' -exec ls -1d {} \; | column
+find . -maxdepth 1 -name "$BASE_VOLUME_NAME" -o -name "$BASE_VOLUME_NAME"-'*' \
+ -exec ls -1d {} \; | column