From a08b7c6c9c660027068579023c66105acb296ed2 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Sat, 19 Apr 2014 14:50:02 +0200 Subject: [PATCH] btrfs-mksnapshot: Correctly detect volume "base name" --- btrfs/mksnapshot/btrfs-mksnapshot | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/btrfs/mksnapshot/btrfs-mksnapshot b/btrfs/mksnapshot/btrfs-mksnapshot index a3fb8ad..d100b45 100755 --- a/btrfs/mksnapshot/btrfs-mksnapshot +++ b/btrfs/mksnapshot/btrfs-mksnapshot @@ -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 -- 2.39.2