From 70e2552ded4cfcd5fc95e678a388a72b3ebd187c Mon Sep 17 00:00:00 2001 From: tracer Date: Wed, 25 Dec 2019 20:01:23 +0100 Subject: [PATCH] initial commit --- Makefile | 13 +++++++++++++ README.md | 2 ++ backupdb | 17 +++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 Makefile create mode 100644 README.md create mode 100755 backupdb diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..88f0737 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +NAME = backupdb +BINDIR = /usr/local/bin +BACKUPDIR = /var/lib/backupdb + +install: + install --mode=755 $(NAME) $(BINDIR) + if [ ! -d $(BACKUPDIR) ]; then mkdir -p $(BACKUPDIR); fi + echo "0 2 * * * root $(BINDIR)/$(NAME)" >> /etc/crontab + +uninstall: + if [ -f $(BINDIR)/$(NAME) ]; then rm $(BINDIR)/$(NAME); fi + if [ -d $(BACKUPDIR) ]; then rm -r $(BACKUPDIR); fi + sed -i '/$(NAME)/d' /etc/crontab diff --git a/README.md b/README.md new file mode 100644 index 0000000..d20de65 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +Simple script to make a daily backup of all MariaDB/MySQL databases. + diff --git a/backupdb b/backupdb new file mode 100755 index 0000000..009b14a --- /dev/null +++ b/backupdb @@ -0,0 +1,17 @@ +#!/bin/bash + +OUTPUT="/var/lib/backupdb" + +cd $OUTPUT + +databases=`mysql -e "SHOW DATABASES;" | tr -d "| " | grep -v Database` + +for db in $databases; do + if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != _* ]]; then + DUMP=$OUTPUT/`date +%Y%m%d`.$db.sql + echo "Dumping database: $db" + if [[ -f ${DUMP}.gz ]]; then rm ${DUMP}.gz; fi + mysqldump --databases $db > $DUMP + gzip $DUMP + fi +done