Quantcast
Viewing latest article 8
Browse Latest Browse All 12

Backup script for GLPI (http://www.glpi-project.org)

If you are using the great GLPI tool, you will notice that the market value of the data inside will increase rapidly. This usually also implicates that it is ‘wise’ to back this data up.

There are many ways to do so using nice plugins, even nicer gui`s and apps. I (headstrong that I am), wanted something very basic and functional, easy to configure, and that will work in an environment that has multiple GLPI installations. Answer to my question: build something for your own.

So i scripted something for Linux that will allow you to backup the entire GLPI tree (where the uploaded files reside), and the sql database.

Because we use a deduped backup storage (datadomain), i dont have to worry about duplicate data. If you need to, then add something to clean the backup store. This script doesn’t account for that Image may be NSFW.
Clik here to view.
:)

This is the script:

#!/bin/bash
# Wrote by Chris
# Goal is to easly backup glpi in a multi installation environment.

GLPI_DIR='/var/www/glpi_0805';
BACKUP_DIR='/backup/nfsloc';
LOGFILE='/var/log/backup.log';

############################################################################
#Dont change anything after this point, unless you know what you are doing #
#No guarantees, une this script at own risk                                #
############################################################################

# Do some generic stuff here
# Add checks if you like :)
#############################
MYSQLDUMP=`which mysqldump`;
AWK=`which awk`;
FIND=`which find`;
DATE=`date +%d.%m.%Y`;
LOGTIME=`date +"%d-%m-%Y %H:%m"`;
DBCONFIG=`find $GLPI_DIR -name "config_db.php"`;
DBNAME=`grep "dbdefault" $DBCONFIG | awk -F '=' '{ gsub(/\047/,""); gsub(/\;/,""); gsub(/ /,""); print $2;}'`;
GLPISIZE=`du -sh $GLPI_DIR`;

#
# Start working....
############################
echo -e "$LOGTIME \t## New backup started ##" >> $LOGFILE;
echo -e "$LOGTIME \tpacking: $GLPISIZE.. into $BACKUP_DIR/backup.$DATE.tar.bz2 ..." >> $LOGFILE;
tar -cjPf $BACKUP_DIR/backup.$DATE.tar.bz2 $GLPI_DIR >> $LOGFILE;
echo -e "$LOGTIME \tCreating mysqldump into $BACKUP_DIR/sqldump.$DATE.sql ..." >> $LOGFILE;
mysqldump $DBNAME > $BACKUP_DIR/sqldump.$DATE.sql;
# Go back to original working directory.
echo -e "$LOGTIME \tAll done..." >> $LOGFILE;
echo "all done! ";

exit 0;

If you want to install this script follow the following instructions:

#This is for Oracle Enterprise Linux / RedHat EL distro`s
#Your environment might be slightly different.
cd /opt
mkdir ./scripts
cd scripts
vi ./backup.sh
#insert the code above into the editor and save the lot using ':wq'
#alter the top of the script to match your environment.
chmod +x ./backup.sh
#next create a symbolic link to the cron.daily, this might be different in your linux distro (see manual pages on your distro using 'man cron').
ln -s /opt/scripts/backup.sh /etc/cron.daily/backup
#monitor the /var/log/backup.log for details

Happy backing up Image may be NSFW.
Clik here to view.
:)

(Dont forget to clean the backup dir on a regular basis if you dont have the luxury of an deduping storage)


Tagged: back, backup, bash, for, GLPI, Linux, OEL, RHEL, Script, tested, up Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing latest article 8
Browse Latest Browse All 12

Trending Articles