You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.1 KiB
Plaintext
53 lines
1.1 KiB
Plaintext
7 years ago
|
#!/usr/bin/env bash
|
||
|
|
||
|
set -e
|
||
|
|
||
|
src="/"
|
||
|
snapshotdir="/backup-snap"
|
||
|
|
||
|
##
|
||
|
# usage : is_btrfs( $path )
|
||
|
# return : whether $path is on a btrfs
|
||
|
# source: makechrootpkg from devtools
|
||
|
##
|
||
|
is_btrfs() {
|
||
|
[[ -e "$1" && "$(stat -f -c %T "$1")" == btrfs ]]
|
||
|
}
|
||
|
|
||
|
delete_snapshot() {
|
||
|
btrfs subvolume delete --commit-after "$snapshotdir"
|
||
|
}
|
||
|
|
||
|
if is_btrfs "$src"; then
|
||
|
if [[ -d "$snapshotdir" ]]; then
|
||
|
delete_snapshot
|
||
|
fi
|
||
|
btrfs subvolume snapshot -r "$src" "$snapshotdir"
|
||
|
src="$snapshotdir"
|
||
|
fi
|
||
|
|
||
|
systemctl is-active postgresql && /usr/local/bin/backup-postgres.sh || true
|
||
|
if systemctl is-active mysqld || systemctl is-active mariadb; then
|
||
|
/usr/local/bin/backup-mysql.sh || true
|
||
|
fi
|
||
|
|
||
|
borg create \
|
||
|
--verbose \
|
||
|
--stats \
|
||
|
--list \
|
||
|
-compression lz4 \
|
||
|
-e '/home/*/.cache/' \
|
||
|
-e /var/tmp \
|
||
|
-e /proc \
|
||
|
-e /sys \
|
||
|
-e /dev \
|
||
|
-e /run \
|
||
|
-e /tmp \
|
||
|
-e /var/cache \
|
||
|
{{ backup_host }}:{{ backup_dir }}::$(date "+%Y%m%d-%H%M%S") "$src"
|
||
|
borg prune -v {{ backup_host }}:{{ backup_dir }} --keep-daily=7 --keep-weekly=4 --keep-monthly=6
|
||
|
|
||
|
if [[ -d "$snapshotdir" ]]; then
|
||
|
delete_snapshot
|
||
|
fi
|