Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Glpi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NoCloud
docker
Glpi
Commits
8cedacf9
Verified
Commit
8cedacf9
authored
7 months ago
by
David Beniamine
Browse files
Options
Downloads
Patches
Plain Diff
Backup and upgrade commands
parent
21f0b14c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
backup.sh
+12
-0
12 additions, 0 deletions
backup.sh
glpi
+56
-2
56 additions, 2 deletions
glpi
with
70 additions
and
2 deletions
.gitignore
+
2
−
0
View file @
8cedacf9
.*.sw?
.*.sw?
.env
.env
backups/
patch
This diff is collapsed.
Click to expand it.
backup.sh
0 → 100755
+
12
−
0
View file @
8cedacf9
#!/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"
This diff is collapsed.
Click to expand it.
glpi
+
56
−
2
View file @
8cedacf9
...
@@ -12,6 +12,8 @@ is_docker() {
...
@@ -12,6 +12,8 @@ is_docker() {
usage
()
{
usage
()
{
echo
-e
"Usage
$0
<command> [args]
\n
"
echo
-e
"Usage
$0
<command> [args]
\n
"
echo
-e
"COMMANDS
\n
"
echo
-e
"COMMANDS
\n
"
echo
"backup"
echo
-e
"
\t
create a database backup"
echo
"bash"
echo
"bash"
echo
-e
"
\t
opens a bash terminal in front container or just run bash"
echo
-e
"
\t
opens a bash terminal in front container or just run bash"
echo
"cache"
echo
"cache"
...
@@ -28,6 +30,8 @@ usage() {
...
@@ -28,6 +30,8 @@ usage() {
echo
-e
"
\t
restart the docker stack or apache2"
echo
-e
"
\t
restart the docker stack or apache2"
echo
"up"
echo
"up"
echo
-e
"
\t
starts the stack"
echo
-e
"
\t
starts the stack"
echo
"upgrade"
echo
-e
"
\t
upgrades glpi"
}
}
if
[
"
$(
is_docker
)
"
-eq
1
]
;
then
if
[
"
$(
is_docker
)
"
-eq
1
]
;
then
...
@@ -48,10 +52,58 @@ mysql="mysql -u $user $db -p$pass"
...
@@ -48,10 +52,58 @@ mysql="mysql -u $user $db -p$pass"
DIR
=
"
$(
dirname
$0
)
"
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
action
=
$1
shift
shift
# Keep actions sorted
# Keep actions sorted
case
$action
in
case
$action
in
"backup"
)
./backup.sh
;;
"bash"
)
"bash"
)
$cmd
bash
$cmd
bash
;;
;;
...
@@ -76,10 +128,12 @@ case $action in
...
@@ -76,10 +128,12 @@ case $action in
"up"
)
"up"
)
$cmdup
$@
$cmdup
$@
;;
;;
"upgrade"
)
upgrade_glpi
;;
*
)
*
)
echo
"ERROR:
No
command
given
"
echo
"ERROR:
unknown
command
: '
$action
'
"
usage
usage
exit
1
exit
1
;;
;;
esac
esac
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment