initial commit

This commit is contained in:
tracer 2019-12-25 20:01:23 +01:00
commit 70e2552ded
3 changed files with 32 additions and 0 deletions

13
Makefile Normal file
View File

@ -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

2
README.md Normal file
View File

@ -0,0 +1,2 @@
Simple script to make a daily backup of all MariaDB/MySQL databases.

17
backupdb Executable file
View File

@ -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