infra/roles/mariadb/templates/mariadb_backup.sh.j2

28 lines
769 B
Django/Jinja

#!/bin/bash
lockfile -l 86400 -r 0 /var/run/maridb_backup.lock || exit 2
print () {
PRINT=true
if [ "$PRINT" = "true" ]; then echo `date +"%F %R:"` "$*" ; fi
}
if [ ! -d {{ mariadb_dump_path }} ]; then
print "path '{{ mariadb_dump_path }}' does not exist, bailing"
exit 1
fi
{% set name = inventory_hostname.split('.')[0] %}
if [ -f {{ mariadb_dump_path }}/{{ name }}.1.sql.gz ]; then
rm {{ mariadb_dump_path }}/{{ name }}.1.sql.gz
fi
if [ -f {{ mariadb_dump_path }}/{{ name }}.sql.gz ]; then
mv {{ mariadb_dump_path }}/{{ name }}.sql.gz {{ mariadb_dump_path }}/{{ name }}.1.sql.gz
fi
# for more compressin, use `gzip --best`
mysqldump --all-databases | gzip > {{ mariadb_dump_path }}/{{ name }}.sql.gz
rm -f /var/run/maridb_backup.lock