From ea8c91ed32218d2923044f563c0dbd874ad63bba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gregor=20Klev=C5=BEe?= Date: Tue, 2 Jan 2018 11:50:46 +0100 Subject: [PATCH] first commit --- README.md | 1 + backupSQL | 24 ++++++++++++++++++++++++ client.cnf | 4 ++++ 3 files changed, 29 insertions(+) create mode 100644 README.md create mode 100755 backupSQL create mode 100644 client.cnf diff --git a/README.md b/README.md new file mode 100644 index 0000000..d721738 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# backupSQL diff --git a/backupSQL b/backupSQL new file mode 100755 index 0000000..b7c5036 --- /dev/null +++ b/backupSQL @@ -0,0 +1,24 @@ +#!/bin/bash + +TIMESTAMP=$(date +"%F") +BACKUP_DIR="/path/to/backup/sql/" +CONFIG_FILE="client.cnf" +MYSQL="/usr/bin/mysql" +MYSQLDUMP="/usr/bin/mysqldump" + +datum=`/bin/date +%Y%m%d` + +databases=`$MYSQL --defaults-extra-file=$CONFIG_FILE -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"` + +for db in $databases; do + echo "Backuping database: " $db + $MYSQLDUMP --defaults-extra-file=$CONFIG_FILE --single-transaction --force --opt --databases ${db} | gzip > "$BACKUP_DIR$db-${datum}.sql.gz" +done + +### Remove files older than 30 days ### +#for file in "$( /usr/bin/find $BACKUP_DIR -type f -mtime +30 )" +#do +# rm $file +#done + +exit 0 diff --git a/client.cnf b/client.cnf new file mode 100644 index 0000000..fe3d4df --- /dev/null +++ b/client.cnf @@ -0,0 +1,4 @@ +[client] +user = backuper +password = password +host = 127.0.0.1