NETGEAR is aware of a growing number of phone and online scams. To learn how to stay safe click here.
Forum Discussion
anna_arun
Jul 23, 2014NETGEAR Expert
SQL DB Auto Backup
Any Inputs on how to do a SQL Data Base Backup automatically on scheduled basis (Free Software)
xeltros
Sep 04, 2014Apprentice
Mysql dump is the way to go, not sure you can backup it automatically without shell, maybe phpmyadmin ? it lets you export the database, maybe it can schedule it (not sure).
Anyway via SQL this script was used to backup a GLPI server, it's a little old and I would advise to test it properly (though it worked perfectly for me).
I'm sorry, this was done for a french-only company so every comment is in french, I will comment if needed.
I deleted some stuff to present a clean script (it was backing up multiple databases and sending some alerts that wouldn't work on the NAS). I let you the part that saves the web files though.
the line that will help you is this one : mysqldump --user root --password=somepassword glpi > /Backups/GLPIDB/$NAME
it is saving the GLPI base as an SQL file named according to the stored value in the $NAME variable.
As already said, since the script was edited and is pretty old, you would want to test it on fake data (or with a fresh backup before testing).
Anyway via SQL this script was used to backup a GLPI server, it's a little old and I would advise to test it properly (though it worked perfectly for me).
I'm sorry, this was done for a french-only company so every comment is in french, I will comment if needed.
I deleted some stuff to present a clean script (it was backing up multiple databases and sending some alerts that wouldn't work on the NAS). I let you the part that saves the web files though.
the line that will help you is this one : mysqldump --user root --password=somepassword glpi > /Backups/GLPIDB/$NAME
it is saving the GLPI base as an SQL file named according to the stored value in the $NAME variable.
As already said, since the script was edited and is pretty old, you would want to test it on fake data (or with a fresh backup before testing).
#!/bin/bash
#on teste si les dossiers existent
if [ ! -d /Backups/GLPIDB/ ]
then mkdir -p /Backups/GLPIDB
fi
if [ ! -d /Backups/GLPI-Files/ ]
then mkdir -p /Backups/GLPI-Files
fi
#On regarde si le log existe, si oui on supprime
if [ -e /scripts/GLPI-Backup.err ]
then rm /scripts/GLPI-Backup.err
fi
#on verifie qu'il reste de la place sur le serveur
DFREE=`df /|awk '{print $3}'|grep [0-9]`
DNEED1=`du /Backups -bc|awk '{print $1}'|tail -n 1`
DNEED=`echo "$DNEED1/4/1024"|bc`
if (( $DFREE < $DNEED ))
then
echo "Espace disque serveur GLPI [critique]" >> /scripts/GLPI-Backup.err
fi
#
#
#sauvegarde de la base GLPI
NAME=`date +"%d-%m-%y_%Hh%M"`_GLPIDB.sql
[color=#FF0000]mysqldump --user root --password=somepassword glpi > /Backups/GLPIDB/$NAME[/color]
RETURN=`echo $?`
# si OK suppression des anciens backups
if [ $RETURN = 0 ]
then
find /Backups/GLPIDB/*.sql -mtime +5 -exec rm {} \;
fi
#SI echec alors log
if [ $RETURN != 0 ]
then
echo "Sauvegarde de la base GLPI [ECHEC]" >> /scripts/GLPI-Backup.err
fi
#si deux backups sont crees dans la meme minute, le plus vieux est efface
if [ -e /Backups/GLPIDB/$NAME.bz2 ]
then rm /Backups/GLPIDB/$NAME.bz2
fi
#compression
bzip2 /Backups/GLPIDB/$NAME
FILESIZE=`du -b /Backups/GLPIDB/$NAME.bz2|awk '{print $1}'`
#on verifie que le fichier n'est pas vide (taille > 1.5M), sinon on log
if (( $FILESIZE < 1500000 ))
then
echo "Compression de la sauvegarde GLPI [ECHEC]" >> /scripts/GLPI-Backup.err
fi
#test de l'archive
bzip2 --test /Backups/GLPIDB/$NAME.bz2
RETURN=`echo $?`
#si le teste echoue ou que le fichier est trop petit on log
if [ $RETURN != 0 ]||(( $FILESIZE < 1500000 ))
then
echo "Test de la sauvegarde GLPI [ECHEC]" >> /scripts/GLPI-Backup.err
fi
#sauvegarde des documents GLPI
tar cjf /Backups/GLPI-Files/`date +"%d-%m-%y_%Hh%m"`_GLPI-FILES.tar.bz2 /var/www/html/glpi/files
RETURN=`echo $?`
#si Echec, on log
if [ $RETURN != 0 ]
then
echo "Sauvegarde des Fichiers GLPI [ECHEC]" >> /scripts/GLPI-Backup.err
fi
Related Content
NETGEAR Academy
Boost your skills with the Netgear Academy - Get trained, certified and stay ahead with the latest Netgear technology!
Join Us!