Skip to content
Snippets Groups Projects
Verified Commit 8cedacf9 authored by David Beniamine's avatar David Beniamine
Browse files

Backup and upgrade commands

parent 21f0b14c
No related branches found
No related tags found
No related merge requests found
.*.sw?
.env
backups/
patch
#!/bin/bash
echo "Backing up glpi DB"
DIR=$(dirname $0)
echo $DIR
cd $DIR
mkdir -p backups
out="backups/mysqldump_$(date +%Y%m%d_%H%M).sql.gz"
. .env
docker-compose exec -T db mariadb-dump --all-databases -u root -p$MYSQL_ROOT_PASSWORD --default-character-set=utf8 | gzip > $out
ls -lh $out
echo "Done"
......@@ -12,6 +12,8 @@ is_docker() {
usage() {
echo -e "Usage $0 <command> [args]\n"
echo -e "COMMANDS\n"
echo "backup"
echo -e "\tcreate a database backup"
echo "bash"
echo -e "\topens a bash terminal in front container or just run bash"
echo "cache"
......@@ -28,6 +30,8 @@ usage() {
echo -e "\t restart the docker stack or apache2"
echo "up"
echo -e "\t starts the stack"
echo "upgrade"
echo -e "\tupgrades glpi"
}
if [ "$(is_docker)" -eq 1 ]; then
......@@ -48,10 +52,58 @@ mysql="mysql -u $user $db -p$pass"
DIR="$(dirname $0)"
upgrade_glpi() {
prefix="/var/www/html"
# Check if current version si the latest
cur_vers=$(echo $($cmd find $prefix/version/ -type f) | cut -d '/' -f 6 | tr -d '\r')
echo "Current GLPI version $cur_vers"
backup_dir="$prefix/../glpi-$cur_vers"
latest_ver=$(curl -s -L https://github.com/glpi-project/glpi/releases/latest | grep '<h1' | tail -n 1 | sed -e 's/<[^>]*>//g' -e 's/\s*//g')
echo "Latest GLPI version $latest_ver"
extract_dir="$prefix/../glpi-$latest_ver"
if [ $cur_vers == $latest_ver ]; then
echo "GLPI is up to date, nothing to do"
return
fi
if [ "$(echo $cur_vers | cut -d . -f 1)" -ne "$(echo $latest_ver | cut -d . -f 1)" ]; then
read -p "New version $latest_ver is a major upgrade do you want to upgrade ? (yes/no)" $answer
if [ "$answer" != "yes" ]; then
echo "Aborting"
return
fi
fi
# Backup DB
$0 backup
# 2 Save old files
$cmd mkdir $backup_dir
$cmd sh -c "rm -rf $backup_dir/*"
$cmd sh -c "mv $prefix/* $backup_dir/"
$cmd ls $backup_dir
# 3 Download glpi files
$cmd mkdir -p $extract_dir
$cmd ls $extract_dir
$cmd curl -L -o glpi_$latest_ver.tar.gz https://github.com/glpi-project/glpi/releases/download/$latest_ver/glpi-$latest_ver.tgz
$cmd ls $extract_dir
$cmd tar xvzf glpi_$latest_ver.tar.gz -C $extract_dir
$cmd ls $extract_dir
$cmd sh -c "mv $extract_dir/glpi/* $prefix/"
$cmd ls $extract_dir
# 4 Restore plugins
$cmd sh -c "cp -rv $backup_dir/plugins/* $prefix/plugins/"
# 5 run php bin/console db:update
$0 console db:update
# Activate plugins
$0 console plugin:install --username=glpi --all
$0 console plugin:activate --all
}
action=$1
shift
# Keep actions sorted
case $action in
"backup")
./backup.sh
;;
"bash")
$cmd bash
;;
......@@ -76,10 +128,12 @@ case $action in
"up")
$cmdup $@
;;
"upgrade")
upgrade_glpi
;;
*)
echo "ERROR: No command given"
echo "ERROR: unknown command : '$action'"
usage
exit 1
;;
esac
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment