This repository has been archived on 2023-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
salt-states_old/podman/files/mysql-dump.sh.jinja

16 lines
790 B
Plaintext
Raw Permalink Normal View History

2022-11-04 08:10:35 +00:00
#!/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
2022-12-15 09:00:18 +00:00
find $BACKUP_DIR/* -type f -name *-sql.gz -mtime +3 -exec rm {} \;
2022-11-04 08:10:35 +00:00