Last active
November 4, 2016 16:34
-
-
Save alexalouit/ac3c56049fa624ef1b57 to your computer and use it in GitHub Desktop.
Backup ISPConfig database (manual)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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