diff --git a/btrfs-snapshots.sh b/btrfs-snapshots.sh index 65586d2..eaac4c9 100755 --- a/btrfs-snapshots.sh +++ b/btrfs-snapshots.sh @@ -101,6 +101,10 @@ for fs in ${BTRFS_VOLUMES}; do date="-$(date +%Y-%m-%d-%H-%M)" target="${name}snapshot${periodity}" if test -n "$device"; then + if mount | grep -q " on $TMP_MNT type "; then + sudo umount "$TMP_MNT" + fi + sudo mount "$device" "$TMP_MNT" if test $dryrun -eq 1; then echo -e "→ \e[1mbackup ${subvol:+subvol $subvol of }$fs on $device\e[0m" echo " " mount "$device" "$TMP_MNT" @@ -112,18 +116,14 @@ for fs in ${BTRFS_VOLUMES}; do fi echo " " umount "$TMP_MNT" else - if mount | grep -q " on $TMP_MNT type "; then - sudo umount "$TMP_MNT" - fi - sudo mount "$device" "$TMP_MNT" sudo btrfs subvolume snapshot "${TMP_MNT}${subvol}" "${TMP_MNT}${target}${date}" #if test -n "$del"; then # for f in $(ls -1 "${TMP_MNT}${target}${date}"-* | tail -n +"$del"); do # sudo btrfs subvolume delete "$f" # done #fi - sudo umount "$TMP_MNT" fi + sudo umount "$TMP_MNT" else echo "ERROR: no device found for $fs" 1>&2 exit 2