Initial LisgloSIPS V2 implementation
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
umask 077
|
||||
dest=/data/backups/mysql
|
||||
install -d -o root -g root -m 0700 "$dest"
|
||||
[ "$(realpath "$dest")" = "/data/backups/mysql" ] || exit 2
|
||||
exec 9>/run/lock/lisglosips-mysql-backup.lock
|
||||
flock -n 9 || { echo "MySQL backup already running" >&2; exit 3; }
|
||||
stamp=$(date -u +%Y%m%dT%H%M%SZ)
|
||||
tmp=$(mktemp -d "$dest/.tmp-$stamp.XXXXXX")
|
||||
trap 'rm -rf "$tmp"' EXIT
|
||||
mysqladmin --protocol=socket ping --silent
|
||||
mysqldump --protocol=socket --all-databases --single-transaction --routines --events --triggers --hex-blob --set-gtid-purged=OFF --no-tablespaces | gzip -9 > "$tmp/all-databases.sql.gz"
|
||||
mysqldump --protocol=socket --single-transaction --routines --events --triggers --hex-blob --set-gtid-purged=OFF --no-tablespaces lisglosips | gzip -9 > "$tmp/lisglosips.sql.gz"
|
||||
mysql --protocol=socket -N -e "SELECT @@version, @@global.gtid_executed, @@global.binlog_format, UTC_TIMESTAMP();" > "$tmp/metadata.tsv"
|
||||
(cd "$tmp" && sha256sum *.gz metadata.tsv > SHA256SUMS)
|
||||
chmod 0600 "$tmp"/*
|
||||
final="$dest/$stamp"
|
||||
mv "$tmp" "$final"
|
||||
trap - EXIT
|
||||
find "$dest" -mindepth 1 -maxdepth 1 -type d -name '20*T*Z' -mtime +14 -exec rm -rf -- {} +
|
||||
echo "$final"
|
||||
Reference in New Issue
Block a user