Automatic Restore of GLPI Backup Script

#! /bin/bash

# extract mysql dump to /backups/mysql/uncompressed

echo "deleting any old mysql dumps." # Delete old glpi.sql

rm /backups/mysql/glpi.sql

echo "DONE!"

new=$(ls -t1 /backups/mysql/ | head -1) # find newest file and assign variable(new):

echo "the newest mysqlsump file is: $new"

# gunzip it to /backups/mysql/glpi.sql

echo "extracting $new now!"

gunzip -c /backups/mysql/$new > /backups/mysql/glpi.sql

echo "file extracted successfully"

sleep 5

# Print start status message.
echo "restoring glpi database"

# import dump into db

mysql -u root -pPASSWORD glpi < /backups/mysql/glpi.sql

# Print end status message.

echo "database restore finished!"

sleep 5

# Remove old folder and add datestamp to it

echo "deleting any old glpi folders."

rm -R /backups/www/var

# find newest tar.gz and assign variable untar to it

untar=$(ls -t1 /backups/www/ | head -1)

echo "the most recent backup is $untar"

# untar www folder

tar -xf /backups/www/$untar -C /backups/www/

# move old glpi folder to glpi_old

mv /var/www/html/glpi /var/www/html/glpi_old

# copy folder to /var/www/html/

echo "copying the glpi folder to the web folder"

cp -r /backups/www/var/www/html/glpi /var/www/html/

echo "glpi folder copied sucessfully"

# change permissions on folder

echo "changing web folder permissions"

sudo chown -R www-data:www-data /var/www/html/glpi

echo "DONE!"

sudo service apache2 restart

echo "GLPI has now been restored to its latest backup."

Leave a Comment

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

Scroll to Top