From a253df0f483aff26d24535373dc5cc106dc98ad6 Mon Sep 17 00:00:00 2001 From: zeus Date: Thu, 14 Apr 2022 11:35:21 +0200 Subject: [PATCH] added database-backup --- bash/mysql-backup.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 bash/mysql-backup.sh 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