Automate GLPI Backups

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.

Create GLPI backup script

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

sudo vim /var/backups/backup-glpi.sh

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

#!/bin/bash

#over-write backups after 7 days

keep_day=7

#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

Create auth.cnf

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:

[client]
user=root
password=PASSWORD

Change PASSWORD to your mysql password and save the file.

Manually run the script

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

bash /backup/backup.sh

When the script finishes running, 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.

Automate with Crontab

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/./backup.sh

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.

If all is good then you have successfully setup automatic GLPI Backups.

2 thoughts on “Automate GLPI Backups”

  1. Pingback: Automatic GLPI Backup Script - GLPI How Too

  2. Pingback: Install GLPI on Ubuntu 22.04 - GLPI How Too

Leave a Comment

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

Scroll to Top