This commit is contained in:
2017-06-12 10:45:18 +10:00
parent 611911c8b1
commit 90792e34f8
2 changed files with 14 additions and 21 deletions

View File

@@ -1,29 +1,30 @@
#!/bin/bash
export PATH=/usr:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin
# ----------------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------------
cleanup() {
if [ "y" == "$MYSQL" ]; then
umount -f /var/lib/mysql-snapshot || true
lvremove -f /dev/vg0/mysql-snapshot || true
/bin/umount -f /var/lib/mysql-snapshot || true
/sbin/lvremove -f /dev/vg0/mysql-snapshot || true
fi
}
mount_snapshot() {
echo "mounting /var/lib/mysql-snapshot..."
mkdir -p /var/lib/mysql-snapshot
mount /dev/vg0/mysql-snapshot /var/lib/mysql-snapshot
/bin/mkdir -p /var/lib/mysql-snapshot
/bin/mount /dev/vg0/mysql-snapshot /var/lib/mysql-snapshot
echo "mounted /var/lib/mysql-snapshot."
}
create_snapshot() {
echo "locking database..."
mysql << EOF
/usr/bin/mysql --defaults-extra-file=/root/.my.cnf << EOF
FLUSH TABLES;
FLUSH TABLES WITH READ LOCK;
system lvcreate --snapshot -n mysql-snapshot -L16G /dev/vg0/mysql
system /sbin/lvcreate --snapshot -n mysql-snapshot -L16G /dev/vg0/mysql
UNLOCK TABLES;
EOF
echo "database locked"
@@ -35,7 +36,7 @@ EOF
# ----------------------------------------------------------------------------
if [ ! -f /etc/systembackup.conf ]; then
echo "systembackup not configured"
echo "systembackup not configured (/etc/systembackup.conf)"
exit 1
fi
@@ -69,7 +70,7 @@ fi
# BACKUP
# ----------------------------------------------------------------------------
BORG_PASSPHRASE=$PASSPHRASE /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 borg create --stats -v \
BORG_PASSPHRASE=$PASSPHRASE /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/bin/borg create --stats -v \
$REPOSITORY::'{hostname}-{now:%Y-%m-%d-%H}' \
/ \
--compression lzma \
@@ -91,12 +92,6 @@ BORG_PASSPHRASE=$PASSPHRASE /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 borg cre
# PRUNE
# ----------------------------------------------------------------------------
BORG_PASSPHRASE=$PASSPHRASE /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 borg prune -v --list $REPOSITORY --prefix '{hostname}-' \
BORG_PASSPHRASE=$PASSPHRASE /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/bin/borg prune -v --list $REPOSITORY --prefix '{hostname}-' \
--keep-hourly=6 --keep-daily=7 --keep-weekly=4 --keep-monthly=6
# ----------------------------------------------------------------------------
# CLEANUP
# ----------------------------------------------------------------------------
cleanup