Automate GLPI Backups

Spread the love


Following on from my last post on backing up GLPI we can easily automate this process so that GLPI is backed up automatically every night so that if needed there will be backups available for restore.

To create an automated backup first we need to create the backup script by typing:

sudo vim /var/backups/

Next we have to add the following text to the script and save it:


#over-write backups after 7 days


#mysql dump to backup folder

mysqldump --defaults-extra-file=/path/to/auth.cnf glpi | gzip > /var/backups/backup_glpi_$(date +"%Y_%m_%d_%H_%M").sql.gz

#tar /var/www/html/glpi to backup folder

tar -czvf /location_to_save_backup/backup_name_$(date +"%Y_%m_%d_%H_%M").tar.gz /var/www/html/glpi

We then need to create the auth.cnf in a location that not all users have access:

sudo vim /path/to/auth.cnf

Add the following to the file:


Manually run the script to make sure that it works as it should:

sudo /backup/

Then check in your backup folder and you should have a new file with backupname_year_month_day_time.sql.gz and a web folder__year_month_day_time.tar.gz.

If the script is working then it is time to add it to crontab so that it runs every night by running:

sudo crontab -e

Add the following to set the job to run every night at 23:30:

30 23 * * * sh /backup/./

Then restart crontab to save the changes:

sudo /etc/init.d/cron restart

Run the following command to make sure that the crontab has been updated:

sudo crontab -l

If you see the entry that you just added to crontab then the script will run automatically at the time set (23:30 in the example above.

Now wait until the allotted time of the backup to make sure that it works.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top