rebalance / defragment is optional

master
Marc Wäckerlin 7 years ago
parent ef9a6966a3
commit 96c3420b4f
  1. 18
      btrfs-snapshots.sh
  2. 2
      install.sh

@ -17,6 +17,7 @@ TMP_MNT=${TMP_MNT:-/var/tmp/btrfs-backup}
vols=() vols=()
del=${DEL} del=${DEL}
dryrun=0 dryrun=0
fast=0
periodity=${0%/*} periodity=${0%/*}
periodity=${periodity##*/} periodity=${periodity##*/}
if [[ $periodity =~ ^cron\... ]]; then if [[ $periodity =~ ^cron\... ]]; then
@ -24,11 +25,12 @@ if [[ $periodity =~ ^cron\... ]]; then
else else
periodity= periodity=
fi fi
case "$periodity" in case "$periodity" in
(.hourly) del=${HOURLY_DEL};; (.hourly) del=${HOURLY_DEL}; fast=1;;
(.daily) del=${DAILY_DEL};; (.daily) del=${DAILY_DEL};;
(.weekly) del=${WEEKLY_DEL};; (.weekly) del=${WEEKLY_DEL}; fast=1;;
(.monthly) del=${MONTHLY_DEL};; (.monthly) del=${MONTHLY_DEL}; fast=1;;
esac esac
while test $# -gt 0; do while test $# -gt 0; do
case "$1" in case "$1" in
@ -39,6 +41,7 @@ OPTIONS
-h, --help show this help -h, --help show this help
-n, --dry-run execute dry run, do not backup, just show commands -n, --dry-run execute dry run, do not backup, just show commands
-f, --fast fast run, do not optimize btrfs (otherwise done daily)
-p, --path <path> add a path that contains a btrfs (sub-) volume -p, --path <path> add a path that contains a btrfs (sub-) volume
(defaults to: ${BTRFS_VOLUMES}) (defaults to: ${BTRFS_VOLUMES})
-m, --mnt <path> temporary mount point (default: ${TMP_MNT}) -m, --mnt <path> temporary mount point (default: ${TMP_MNT})
@ -74,6 +77,7 @@ appended to the snapshot name, and the expiry is set meaningfull:
EOF EOF
exit;; exit;;
(-n|--dry-run) dryrun=1;; (-n|--dry-run) dryrun=1;;
(-f|--fast) fast=1;;
(-p|--path) shift; vols+=( "$1" );; (-p|--path) shift; vols+=( "$1" );;
(-m|--mnt) shift; TMP_MNT="$1";; (-m|--mnt) shift; TMP_MNT="$1";;
(-d|--del) shift; del="$1";; (-d|--del) shift; del="$1";;
@ -126,6 +130,10 @@ for fs in ${BTRFS_VOLUMES}; do
done done
fi fi
echo " " umount "$TMP_MNT" echo " " umount "$TMP_MNT"
if test $fast -eq 0; then
echo " " btrfs filesystem defragment ${fs}
echo " " btrfs balance start ${fs}
fi
else else
sudo btrfs subvolume snapshot "${TMP_MNT}${subvol}" "${TMP_MNT}${target}${date}" sudo btrfs subvolume snapshot "${TMP_MNT}${subvol}" "${TMP_MNT}${target}${date}"
if test -n "$del"; then if test -n "$del"; then
@ -135,6 +143,10 @@ for fs in ${BTRFS_VOLUMES}; do
fi fi
fi fi
sudo umount "$TMP_MNT" sudo umount "$TMP_MNT"
if test $fast -eq 0; then
sudo btrfs filesystem defragment ${fs}
sudo btrfs balance start ${fs}
fi
else else
echo "ERROR: no device found for $fs" 1>&2 echo "ERROR: no device found for $fs" 1>&2
exit 2 exit 2

@ -4,7 +4,7 @@ for f in hourly daily weekly monthly; do
sudo cp btrfs-snapshots.sh /etc/cron.$f/btrfs-snapshots; sudo cp btrfs-snapshots.sh /etc/cron.$f/btrfs-snapshots;
done done
if ! test -e /etc/btrfs-snapshots.conf; then if ! test -e /etc/btrfs-snapshots.conf; then
cat > /etc/btrfs-snapshots.conf <<EOF sudo tee /etc/btrfs-snapshots.conf > /dev/null <<EOF
HOURLY_DEL=4 HOURLY_DEL=4
DAILY_DEL=3 DAILY_DEL=3
WEEKLY_DEL=2 WEEKLY_DEL=2

Loading…
Cancel
Save