mariadb: Add missing backup script
This commit is contained in:
parent
06ac7fc7cc
commit
4cc67c2c27
1 changed files with 32 additions and 0 deletions
32
roles/mariadb/files/mariadb-backup.sh
Executable file
32
roles/mariadb/files/mariadb-backup.sh
Executable file
|
@ -0,0 +1,32 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
umask 077
|
||||
|
||||
DESTDIR="/export/backup"
|
||||
DATE="$(date +%Y-%m-%d)"
|
||||
|
||||
if [ ! -d "$DESTDIR" ]; then
|
||||
echo "ERR: MariaDB backup directory [${DESTDIR}] does not exist" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$DESTDIR" && {
|
||||
find . -xdev -mindepth 2 -maxdepth 2 -type f -mtime +7 \
|
||||
-execdir rm -f -- {} \;
|
||||
find . -xdev -depth -mindepth 1 -maxdepth 1 -type d -empty \
|
||||
-execdir rmdir -- {} \;
|
||||
}
|
||||
|
||||
DESTDIR="${DESTDIR}/${DATE}"
|
||||
mkdir -p "$DESTDIR"
|
||||
|
||||
for db in $(mysql -e "show databases" -s) ; do
|
||||
case "$db" in
|
||||
Database|information_schema|performance_schema)
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
mysqldump -E --add-drop-table "$db" | gzip > "${DESTDIR}/${db}.${DATE}.gz"
|
||||
done
|
Loading…
Add table
Reference in a new issue