reorg and new lizardfs-snapshots.sh

master
Marc Wäckerlin 7 years ago
parent 38acf262f8
commit 182df98cef
  1. 36
      README.md
  2. 20
      btrfs/README.md
  3. 0
      btrfs/btrfs-snapshots.sh
  4. 17
      install.sh
  5. 25
      lizardfs/README.md
  6. 123
      lizardfs/lizsrdfs-snapshots.sh

@ -1,29 +1,17 @@
Use BTRFS Snapshots For Backups Backup And Snapshot Scripts
=============================== ===========================
btrfs-snapshots.sh
------------------
Creates a snapshot for all btrfs volumes specified. Snapshot is named
from the subvol name or if there is no subvol, from the path by
appending `-snapshot-YYYY-MM-DD-HH-mm`.
To create regular snapshots on a daily base, just run:
sudo cp btrfs-snapshots.sh /etc/cron.daily/btrfs-snapshots
If `btrfs-snapshots` is run from a `cron.daily`, `cron.hourly`,
`cron. monthly` or `cron.weekly` directory, the periodity is
automatically appended to the snapshot name, and the expiry is set
meaningfull.
Try: `btrfs-snapshots.sh --help`
- [BTRFS](btrfs/README.md)
- [LizardFs](lizardfs/README.md)
Installation Installation
------------ ------------
Just call `./install.sh` to install all cron jobs. Then there will Just call `./install.sh path/script` to install all cron jobs. Then
always be the last 24 hourly backups, the last 7 daily backups, tha there will always be the last 24 hourly backups, the last 7 daily
last 4 weekly backups and all monthly backups of all your btrfs backups, the last 4 weekly backups and all monthly backups, unless you
filesystems mounted in `/etc/fstab`. configure something different.
e.g.:
./install.sh lizardfs/lizsrdfs-snapshots.sh

@ -0,0 +1,20 @@
Use BTRFS Snapshots For Backups
===============================
btrfs-snapshots.sh
------------------
Creates a snapshot for all btrfs volumes specified. Snapshot is named
from the subvol name or if there is no subvol, from the path by
appending `-snapshot-YYYY-MM-DD-HH-mm`.
To create regular snapshots on a daily base, just run:
sudo cp btrfs-snapshots.sh /etc/cron.daily/btrfs-snapshots
If `btrfs-snapshots` is run from a `cron.daily`, `cron.hourly`,
`cron. monthly` or `cron.weekly` directory, the periodity is
automatically appended to the snapshot name, and the expiry is set
meaningfull.
Try: `btrfs-snapshots.sh --help`

@ -1,13 +1,12 @@
#!/bin/bash #!/bin/bash
if ! test -x "$1"; then
echo "ERROR: call $0 path/script" 1>&2
exit 1
fi
for f in hourly daily weekly monthly; do for f in hourly daily weekly monthly; do
sudo cp btrfs-snapshots.sh /etc/cron.$f/btrfs-snapshots; name=${1##*/}
echo "installing $1 to /etc/cron.$f/${name%.*}"
sudo cp $1 /etc/cron.$f/${name%.*}
done done
if ! test -e /etc/btrfs-snapshots.conf; then
sudo tee /etc/btrfs-snapshots.conf > /dev/null <<EOF
HOURLY_DEL=4
DAILY_DEL=3
WEEKLY_DEL=2
MONTHLY_DEL=3
EOF
fi

@ -0,0 +1,25 @@
LizardFS Snapshots And Backups
==============================
Creates a lizardfs snapshot of all sources to a destination. If
`--del` is specified, only the given number of snapshots is kept,
older snapshots are deleted.
To create regular snapshots on a daily base, just run:
sudo cp btrfs-snapshots.sh /etc/cron.daily/btrfs-snapshots
If `lizardfs-snapshots` is run from a `cron.daily`, `cron.hourly`,
`cron. monthly` or `cron.weekly` directory, the periodity is
automatically appended to the snapshot name, and the expiry is set
meaningfull. Otherwise the name is `manual` and nothing is expired by
default.
You can create a configuration file, specifiying some defaults,
e.g. `/etc/lizardfs-snapshots.conf`:
SOURCES=( /var/volumes/configs /var/volumes/volumes )
DESTINATION=/var/volumes/backup/snapshots
MONTHLY_DEL=13
Try: `lizardfs-snapshots.sh --help`

@ -0,0 +1,123 @@
#!/bin/bash -e
# defaults
HOURLY_DEL=25
DAILY_DEL=8
WEEKLY_DEL=5
MONTHLY_DEL=
SOURCES=()
DESTINATION=
# overwrite defaults in configs
if test -e /etc/lizardfs-snapshots.conf; then
. /etc/lizardfs-snapshots.conf
fi
if test -e ~/.lizardfs-snapshots; then
. ~/.lizrdfs-snapshots
fi
# evaluate commandline
del=
periodity=${0%/*}
periodity=${periodity##*/}
if [[ $periodity =~ ^cron\... ]]; then
periodity=${periodity#cron}
else
periodity=
fi
case "$periodity" in
(.hourly) del=${HOURLY_DEL};;
(.daily) del=${DAILY_DEL};;
(.weekly) del=${WEEKLY_DEL};;
(.monthly) del=${MONTHLY_DEL};;
(*) periodity=".manual";;
esac
while test $# -gt 0; do
case "$1" in
(-h|--help) cat <<EOF
$0 [OPTIONS] [[SOURCES...] DESTINATION]
OPTIONS
-h, --help show this help
-n, --dry-run execute dry run, do not backup, just show commands
-d, --del <number> delete old snapshots beginning at <numbers>-th
CONFIGURATION FILE
You can have a configuration file lizardfs-snapshots.conf either in /etc or in your home.
This may define the following bash variables:
HOURLY_DEL, DAILY_DEL, WEEKLY_DEL, MONTHLY_DEL
defining the parameter --del for hourly, daily, weekly, monthly
SOURCES bash array that defines the sources to backup
DESTINATION snapshot target path
DESCRIPTION
To create regular snapshots on a daily base, just run:
sudo cp lizardfs-snapshots.sh /etc/cron.daily/lizardfs-snapshots
If lizardfs-snapshots is run from a cron.daily, cron.hourly,
cron. monthly or cron.weekly directory, the periodity is automatically
appended to the snapshot name, and the expiry is set meaningfull:
- hourly → keep only 24 hours, --del 25
- daily → keep only 7 days, --del 8
- weekly → keep only 4 weeks, --del 5
- monthly → old snapshots are not deleted
EOF
exit;;
(-n|--dry-run) dryrun=1;;
(-d|--del) shift; del="$1";;
(*) break;;
esac
if test $# -lt 1; then
echo "ERROR: missing argument, try $0 --help" 1>&2
exit 1
fi
shift
done
while test $# -gt 1; do
SOURCES+=("$1")
shift
done
if test $# -eq 1; then
DESTINATION="$1"
fi
if test -z "${SOURCES[*]}"; then
echo "ERROR: no sources specified, try $0 --help" 1>&2
exit 1
fi
if test -z "${DESTINATION}"; then
echo "ERROR: no destination specified, try $0 --help" 1>&2
exit 1
fi
if $dryrun -eq 0 && ! ( test -d "${DESTINATION}" || mkdir -p "${DESTINATION}" ); then
echo "ERROR: cannot create destination path '$DESTINATION', try $0 --help" 1>&2
exit 1
fi
date="-$(date +%Y-%m-%d-%H-%M)"
for src in "${SOURCES[@]}"; do
target="${src##*/}${periodity}"
if test $dryrun -eq 1; then
echo -e "→ \e[1mbackup $src\e[0m"
echo " " "lizardfs snapshot '${src}' '${DESTINATION}/${target}${date}'"
if test -n "$del"; then
for f in $(ls -d1 "${DESTINATION}/${target}"-* | sort -r | tail -n +"$del"); do
echo " " "rm -rf '$f'"
done
fi
else
echo -e "→ \e[1mbackup $src\e[0m"
lizardfs snapshot "${src}" "${DESTINATION}/${target}${date}"
if test -n "$del"; then
for f in $(ls -d1 "${DESTINATION}/${target}"-* | sort -r | tail -n +"$del"); do
rm -rf "$f"
done
fi
fi
done
Loading…
Cancel
Save