diff --git a/bash/mysql-backup.sh b/bash/mysql-backup.sh new file mode 100755 index 0000000..a2ddcb4 --- /dev/null +++ b/bash/mysql-backup.sh @@ -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