Skip to content

Instantly share code, notes, and snippets.

@alexalouit
Last active November 4, 2016 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexalouit/ac3c56049fa624ef1b57 to your computer and use it in GitHub Desktop.
Save alexalouit/ac3c56049fa624ef1b57 to your computer and use it in GitHub Desktop.
Backup ISPConfig database (manual)
#!/bin/bash
#
# cron ex: 0 3 1 * * /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /root/scripts/backup-dbispconfig.sh >> /root/scripts/cron.log
DIR="/root/backup/"
MYSQLUSER="" # FOR SECURITY REASONS, CREATE AN READ ONLY USER FOR BACKUP!
# eg (as root): CREATE USER 'backup'@'localhost' IDENTIFIED BY 'RANDOMPASSWORD'; GRANT SELECT ON dbispconfig.* TO 'backup'@'localhost'; FLUSH PRIVILEGES;
MYSQLPASSWORD=""
MYSQLDATABASE="dbispconfig"
DATE=$(date +"%Y%m%d")
HOST=$(hostname)
if [ ! -d "$DIR" ];
then
mkdir $DIR;
if [ ! -d "$DIR" ];
then
print "ALERT (backup-ispconfig.sh): I can't create directory!";
exit 0;
fi
fi
mysqldump --lock-tables=false -u $MYSQLUSER -p$MYSQLPASSWORD $MYSQLDATABASE | gzip > $DIR/$DATE-$HOST-$MYSQLDATABASE.sql.gz;
if [ ! "$?" -eq 0 ];
then
print "ALERT (backup-ispconfig.sh): I don't have the correct access to the database!";
exit 0;
fi
if [ ! -f "$DIR/$DATE-$HOST-$MYSQLDATABASE.sql.gz" ];
then
print "ALERT (backup-ispconfig.sh): I can't create file!";
exit 0;
fi
#TODO: delete oldest file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment