added database-backup

master
zeus 2022-04-14 11:35:21 +02:00
parent 4b66efff9a
commit a253df0f48
1 changed files with 6 additions and 0 deletions

6
bash/mysql-backup.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
#daily database-backup with 1 week retention, basics taken from https://ma.ttias.be/mysql-back-up-take-a-mysqldump-with-each-database-in-its-own-sql-file/
mkdir -p /backup/$(date '+%F'); mysql -N -e 'show databases' | while read dbname; do mysqldump --complete-insert --routines --triggers --single-transaction "$dbname" > /backup/$(date '+%F')/"$dbname".sql; done && sync && sleep 1 && find /backup/ -mindepth 1 -mtime +8 -delete && sync && sleep 1 && find /backup/ -type d -empty -delete
# cronjob-version (escaped "%" for date):
#0 3 * * * root mkdir -p /backup/$(date '+\%F'); mysql -N -e 'show databases' | while read dbname; do mysqldump --complete-insert --routines --triggers --single-transaction "$dbname" > /backup/$(date '+\%F')/"$dbname".sql; done && sync && sleep 1 && find /backup/ -mindepth 1 -mtime +8 -delete && sync && sleep 1 && find /backup/ -type d -empty -delete