From 55ba4420ab61de0c579e83f407e95bba30e15927 Mon Sep 17 00:00:00 2001 From: Simon Cornet Date: Wed, 7 Sep 2022 14:16:20 +0200 Subject: [PATCH] [MySQL] Added backup script --- Linux/mysql_backup.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Linux/mysql_backup.sh diff --git a/Linux/mysql_backup.sh b/Linux/mysql_backup.sh new file mode 100644 index 0000000..08d084c --- /dev/null +++ b/Linux/mysql_backup.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# config section +date=`date +%Y-%m-%d` +backup_dir='/mnt/mysql_backup' +retention=3 + +# create backup +mkdir -p $backup_dir + +# database backup +for DB in $(mysql -e 'show databases' -s --skip-column-names|grep -v 'information_schema\|performance_schema'); do + mysqldump $DB > "$backup_dir/$date.$DB.sql"; +done + +# delete old backups +find $backup_dir -type f -mtime +$retention -name '*.sql' -execdir rm -- '{}' \; \ No newline at end of file