#!/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
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"
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"
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