fixed option -p; better infos on dry run

master
Marc Wäckerlin 7 years ago
parent 33eb0a20d1
commit bf2a4e8415
  1. 40
      btrfs-snapshots.sh

@ -49,34 +49,46 @@ EOF
fi fi
shift shift
done done
if test -n "${vols[*]}"; then
BTRFS_VOLUMES=${BTRFS_VOLUMES:-$(awk '!/^#/ && $3=="btrfs" {print $2}' /etc/fstab)} BTRFS_VOLUMES="${vols[*]}"
TMP_MNT=${TMP_MNT:-/var/tmp/btrfs-backup} fi
test -d "${TMP_MNT}" || mkdir -p "${TMP_MNT}" test -d "${TMP_MNT}" || mkdir -p "${TMP_MNT}"
for fs in ${BTRFS_VOLUMES}; do for fs in ${BTRFS_VOLUMES}; do
device=$(mount | awk '$3=="'$fs'" && $5=="btrfs" {print $1}') device=$(mount | awk '$3=="'$fs'" && $5=="btrfs" {print $1}')
subvol=$(mount | awk '$3=="'$fs'" && $5=="btrfs" {split(substr($6, 2, length($6)-2), res, ","); for (r in res) {if (res[r]~/^subvol=/) {sub(/^subvol=/,"" , res[r]); print res[r]}}}') subvol=$(mount | awk '$3=="'$fs'" && $5=="btrfs" {split(substr($6, 2, length($6)-2), res, ","); for (r in res) {if (res[r]~/^subvol=/) {sub(/^subvol=/,"" , res[r]); print res[r]}}}')
if test -n "$subvol"; then if test -n "$subvol"; then
name=${subvol} if test "$subvol" = "/@"; then
name=${subvol}
else
name=${subvol}-
fi
else else
if test "$fs" = "/"; then if test "$fs" = "/"; then
name="@root" name="/"
else else
name=${fs#/} name=${fs#/}
name=${name%/} name=${name%/}
name=${name//\//-} name=/${name//\//-}-
fi fi
fi fi
target="${name}-snapshot-$(date +%Y-%m-%d-%H-%M)" target="${name}snapshot-$(date +%Y-%m-%d-%H-%M)"
if test $dryrun -eq 1; then if test -n "$device"; then
echo btrfs subvolume snapshot "${TMP_MNT}${subvol}" "${TMP_MNT}/${target}" if test $dryrun -eq 1; then
else echo -e "→ \e[1mbackup ${subvol:+subvol $subvol of }$fs on $device\e[0m"
if mount | grep -q " on $TMP_MNT type "; then echo " " mount "$device" "$TMP_MNT"
echo " " btrfs subvolume snapshot "${TMP_MNT}${subvol}" "${TMP_MNT}${target}"
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}"
sudo umount "$TMP_MNT" sudo umount "$TMP_MNT"
fi fi
sudo mount "$device" "$TMP_MNT" else
sudo btrfs subvolume snapshot "${TMP_MNT}${subvol}" "${TMP_MNT}/${target}" echo "ERROR: no device found for $fs" 1>&2
sudo umount "$TMP_MNT" exit 2
fi fi
done done

Loading…
Cancel
Save