|
|
|
@ -17,6 +17,7 @@ TMP_MNT=${TMP_MNT:-/var/tmp/btrfs-backup} |
|
|
|
|
vols=() |
|
|
|
|
del=${DEL} |
|
|
|
|
dryrun=0 |
|
|
|
|
fast=0 |
|
|
|
|
periodity=${0%/*} |
|
|
|
|
periodity=${periodity##*/} |
|
|
|
|
if [[ $periodity =~ ^cron\... ]]; then |
|
|
|
@ -24,11 +25,12 @@ if [[ $periodity =~ ^cron\... ]]; then |
|
|
|
|
else |
|
|
|
|
periodity= |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
case "$periodity" in |
|
|
|
|
(.hourly) del=${HOURLY_DEL};; |
|
|
|
|
(.hourly) del=${HOURLY_DEL}; fast=1;; |
|
|
|
|
(.daily) del=${DAILY_DEL};; |
|
|
|
|
(.weekly) del=${WEEKLY_DEL};; |
|
|
|
|
(.monthly) del=${MONTHLY_DEL};; |
|
|
|
|
(.weekly) del=${WEEKLY_DEL}; fast=1;; |
|
|
|
|
(.monthly) del=${MONTHLY_DEL}; fast=1;; |
|
|
|
|
esac |
|
|
|
|
while test $# -gt 0; do |
|
|
|
|
case "$1" in |
|
|
|
@ -39,6 +41,7 @@ OPTIONS |
|
|
|
|
|
|
|
|
|
-h, --help show this help |
|
|
|
|
-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 |
|
|
|
|
(defaults to: ${BTRFS_VOLUMES}) |
|
|
|
|
-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 |
|
|
|
|
exit;; |
|
|
|
|
(-n|--dry-run) dryrun=1;; |
|
|
|
|
(-f|--fast) fast=1;; |
|
|
|
|
(-p|--path) shift; vols+=( "$1" );; |
|
|
|
|
(-m|--mnt) shift; TMP_MNT="$1";; |
|
|
|
|
(-d|--del) shift; del="$1";; |
|
|
|
@ -126,6 +130,10 @@ for fs in ${BTRFS_VOLUMES}; do |
|
|
|
|
done |
|
|
|
|
fi |
|
|
|
|
echo " " umount "$TMP_MNT" |
|
|
|
|
if test $fast -eq 0; then |
|
|
|
|
echo " " btrfs filesystem defragment ${fs} |
|
|
|
|
echo " " btrfs balance start ${fs} |
|
|
|
|
fi |
|
|
|
|
else |
|
|
|
|
sudo btrfs subvolume snapshot "${TMP_MNT}${subvol}" "${TMP_MNT}${target}${date}" |
|
|
|
|
if test -n "$del"; then |
|
|
|
@ -135,6 +143,10 @@ for fs in ${BTRFS_VOLUMES}; do |
|
|
|
|
fi |
|
|
|
|
fi |
|
|
|
|
sudo umount "$TMP_MNT" |
|
|
|
|
if test $fast -eq 0; then |
|
|
|
|
sudo btrfs filesystem defragment ${fs} |
|
|
|
|
sudo btrfs balance start ${fs} |
|
|
|
|
fi |
|
|
|
|
else |
|
|
|
|
echo "ERROR: no device found for $fs" 1>&2 |
|
|
|
|
exit 2 |
|
|
|
|