16 lines
790 B
Plaintext
16 lines
790 B
Plaintext
|
#!/bin/bash
|
||
|
umask 0077
|
||
|
BACKUP_DIR={{ pillar.containers.mariadb.backup_dir }}
|
||
|
databases=$(podman exec -it mariadb mysql -B -u root -p{{ pillar.containers.mariadb.env.MYSQL_ROOT_PASSWORD }} -e "SHOW DATABASES;" | tr -d "| " | grep -v Database)
|
||
|
|
||
|
for db in ${databases[@]}; do
|
||
|
db=${db::-1}
|
||
|
if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] && [[ "$db" != "sys" ]]; then
|
||
|
echo "Dumping database: $db"
|
||
|
podman exec -it mariadb mysqldump -u root -p{{ pillar.containers.mariadb.env.MYSQL_ROOT_PASSWORD }} --databases $db | gzip > ${BACKUP_DIR}/$(date +"%Y-%m-%d_%H-%M-%S")_$db-sql.gz
|
||
|
fi
|
||
|
done
|
||
|
# Delete the files older than 3 days
|
||
|
find $BACKUP_DIR/* -type f -name *-sql.gz -mtime +3 -exec rm {} \;
|
||
|
|