Skip to content

Commit

Permalink
backups restoration scripts + code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
medilies committed Dec 12, 2021
1 parent 7b766c8 commit 9fa5a83
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 57 deletions.
106 changes: 82 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# GLPI on Docker

<img src="https://glpi-project.org/wp-content/uploads/2017/03/logo-glpi-bleu-1.png" alt="GLPI Logo" width="75"/>
<img src="https://www.docker.com/sites/default/files/d8/styles/role_icon/public/2019-07/vertical-logo-monochromatic.png?itok=erja9lKc" alt="Docker Logo" width="75"/>
<img src="https://www.mysql.com/common/logos/logo-mysql-170x115.png" alt="MySQL Logo" width="75"/>
Expand All @@ -7,44 +9,100 @@

---

The shell scripts will automatically download and install:
## Get started

- GLPI 9.5.5
- Datainjection 2.9.0
- Mreporting 1.7.3
- Addressing 2.9.0
- Fusioninventory 3.0
- Ocsinventoryng 1.7.3
- Print pdf 2.0.0
- Shellcommands 3.0.0
Note that we focus on GLPI 9.5.5 and its compatible plugins

# Setup
1. Datainjection 2.9.0
2. Mreporting 1.7.3
3. Addressing 2.9.0
4. Fusioninventory 3.0
5. Ocsinventoryng 1.7.3
6. Print pdf 2.0.0
7. Shellcommands 3.0.0

Note:
### Requirements

- You must have docker on your system ( ik kinda obv :p )
- The installation may take so long on a hard disk so be patient with your HDD
Must have docker & docker-compose on your system!

## Fast get up & running
Download the latest release from this repo.

`cd` to the cloned repo folder then run `docker-compose up --build`
### Default installation

`bash` into **<stack_name>\_glpi_1** (`docker container exec -it [glpi] bash`) and run `/scripts/install.bash`
Launch the stack (Assuming that `docker-compose.yml` is within the directory `glpi`)

## Customization
```shell
cd glpi
docker-compose up
```

Before starting the containers :
Install GLPI and our selected plugins

```shell
docker container exec -it glpi_web_1 /scripts/full_setup.sh
docker container exec -it glpi_db_1 /scripts/setup.sh
```

The previous commands mainly install GLPI and its plugins, Set contabs to backup DB & web files daily.

Now grap your favorite browser and enjoy managing your infrastructure with GLPI ;D

## Backup & Restoring

### Manual Backups

- DB backup

```shell
docker container exec -it glpi_db_1 /scripts/db_backup.sh
```

- Web files backup

```shell
docker container exec -it glpi_web_1 /scripts/web_files_backup.sh
```

Backups are dumped into their respective containers `/backups` folder.

NOTE: backup folder are mapped to the host system:

- It is vital for the security of your deployment to edit the sercrets values within `./secrets`
- Open `./docker-compose.yml` and edit the the lines where you see the comment `# CHANGE` to suit your environment
- DB: `glpi/stack_dumps/db_backups:/backups`
- WEB: `glpi/stack_dumps/web_files_backups:/backups`

### Manual backups restorations

# TODO:
- DB restoration

```shell
docker container exec -it glpi_db_1 /scripts/db_restore.sh
```

- Web files restoration

```shell
docker container exec -it glpi_web_1 /scripts/web_files_restore.sh
```

Both commands will ask you for the backup absolute path (`/backups/<timestamp>_glpi_db_backup.sql`,
`/backups/<timestamp>_glpi_web_backup.tar.gz`).

### Crontab backups

If you have followed the default installation, backup scripts are set to run every 8 hours (`0 */8 * * *`). That is set within `DB:/scripts/cron_db_backup.sh` `WEB:/scripts/cron_web_files_backer.sh`

## Stack customization

Before starting the containers :

- It is vital for the security of your deployment to edit the sercrets values within `./secrets`
- Open `./docker-compose.yml` and edit the the lines where you see the comment `# CHANGE` to suit your environment

## TODO:

- Automate "GRANT SELECT ON mysql.time_zone_name TO 'glpi_user'@'%'; FLUSH PRIVILEGES;"
- Automate Database backups
- Automate GLPI web folden backups
- Add interactivity to the shell scripts to select plugins to install and which versions
- Integrate OCS

## LICENCE

The project is under the MIT licence so feel free to fork it and contribute to it :)
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
- admin-db
volumes:
- database:/var/lib/mysql # CHANGE
- ./glpidb/scripts:/scripts
- ./glpidb/scripts:/scripts # [OPTIONAL for live editing / dev]
- ./stack_dumps/db_backups:/backups
command: mysqld --default-authentication-plugin=mysql_native_password
secrets:
Expand Down Expand Up @@ -53,8 +53,8 @@ services:
ports:
- 50080:80 # CHANGE
volumes:
- ./glpi/scripts:/scripts
- ./stack_dumps/web_files:/backups
- ./glpi/scripts:/scripts # [OPTIONAL for live editing / dev]
- ./stack_dumps/web_files_backups:/backups
secrets:
- DB_SERVER
- MYSQL_DATABASE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
# -----------------------------------------------------------------------------

# Script to create a cronjob for web directory backup
echo "0 */4 * * * root /scripts/files_backer.sh" >/etc/cron.d/files_backer &&
chown root /etc/cron.d/files_backer &&
chgrp root /etc/cron.d/files_backer &&
chmod 0700 /etc/cron.d/files_backer &&
# crontab -u root /etc/cron.d/files_backer &&
echo "0 */8 * * * root /scripts/web_files_backer.sh" >/etc/cron.d/web_files_backer &&
chown root /etc/cron.d/web_files_backer &&
chgrp root /etc/cron.d/web_files_backer &&
chmod 0700 /etc/cron.d/web_files_backer &&
# crontab -u root /etc/cron.d/web_files_backer &&
/etc/init.d/cron restart

# NOTE
Expand Down
7 changes: 5 additions & 2 deletions glpi/scripts/install.sh → glpi/scripts/full_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
# -----------------------------------------------------------------------------

/scripts/install_glpi.sh
/scripts/files_backer_cron.sh

/scripts/cron_web_files_backer.sh

# plugins installation
/scripts/install_fusioninventory.sh
/scripts/_install_datainjection.sh
/scripts/install_datainjection.sh
/scripts/_install_mreporting.sh
/scripts/install_pdf.sh
/scripts/install_addressing.sh
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
# Script to create a web directory backup

TIMESTAMP=$(date +"%FT%H-%M-%S%z")
BACKUP_FILE_NAME=glpi_web_backup_"$TIMESTAMP"
BACKUP_FILE_NAME="$TIMESTAMP"_glpi_web_backup

tar ckzf /backups/"$BACKUP_FILE_NAME".tar.gz /var/www/html
tar ckzf /backups/"$BACKUP_FILE_NAME".tar.gz -C /var/www html
16 changes: 16 additions & 0 deletions glpi/scripts/web_files_restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
#
# Writter : Boudouma Mohamed Ilies (medilies)
# Github repo: https://github.com/medilies/glpi
# My Linkedin: https://www.linkedin.com/in/medilies/
# -----------------------------------------------------------------------------

#

echo "Enter the backup archive path:"
read -r WEB_FILES_BACKUP

tar -xzf "$WEB_FILES_BACKUP" -C /var/www

# Just in case ... :p
/scripts/cron_web_files_backup.sh
2 changes: 0 additions & 2 deletions glpidb/init.sql

This file was deleted.

15 changes: 15 additions & 0 deletions glpidb/scripts/cron_db_backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
#
# Writter : Boudouma Mohamed Ilies (medilies)
# Github repo: https://github.com/medilies/glpi
# My Linkedin: https://www.linkedin.com/in/medilies/
# -----------------------------------------------------------------------------

# Script to create a cronjob for glpi database backup

echo "0 */8 * * * root /scripts/db_backup.sh" >/etc/cron.d/db_backup &&
chown root /etc/cron.d/db_backup &&
chgrp root /etc/cron.d/db_backup &&
chmod 0700 /etc/cron.d/db_backup &&
# crontab -u root /etc/cron.d/db_backup &&
/etc/init.d/cron restart
10 changes: 8 additions & 2 deletions glpidb/scripts/db_Timezones.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#!/bin/bash

# Grants access to GLPI's database user access to timezones table

MYSQL_DATABASE=$(cat /run/secrets/MYSQL_DATABASE)
MYSQL_USER=$(cat /run/secrets/MYSQL_USER)
MYSQL_PASSWORD=$(cat /run/secrets/MYSQL_ROOT_PASSWORD)
MYSQL_ROOT_PASSWORD=$(cat /run/secrets/MYSQL_ROOT_PASSWORD)

Q1="USE $MYSQL_DATABASE;"
Q2="GRANT SELECT ON mysql.time_zone_name TO '$MYSQL_USER'@'%';"
Q3="FLUSH PRIVILEGES;"

mysql -uroot -p"$MYSQL_PASSWORD" -e "USE $MYSQL_DATABASE; GRANT SELECT ON mysql.time_zone_name TO '$MYSQL_USER'@'%'; FLUSH PRIVILEGES;"
mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "$Q1 $Q2 $Q3"
6 changes: 3 additions & 3 deletions glpidb/scripts/db_backer.sh → glpidb/scripts/db_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

MYSQL_DATABASE=$(cat /run/secrets/MYSQL_DATABASE)
# MYSQL_USER=$(cat /run/secrets/MYSQL_USER)
MYSQL_PASSWORD=$(cat /run/secrets/MYSQL_ROOT_PASSWORD)
MYSQL_ROOT_PASSWORD=$(cat /run/secrets/MYSQL_ROOT_PASSWORD)

TIMESTAMP=$(date +"%FT%H-%M-%S%z")
BACKUP_FILE_NAME=glpi_db_backup_"$TIMESTAMP"
BACKUP_FILE_NAME="$TIMESTAMP"_glpi_db_backup

mysqldump --user=root --password="$MYSQL_PASSWORD" "$MYSQL_DATABASE" >/backups/"$BACKUP_FILE_NAME".sql
mysqldump --user=root --password="$MYSQL_ROOT_PASSWORD" "$MYSQL_DATABASE" >/backups/"$BACKUP_FILE_NAME".sql
17 changes: 17 additions & 0 deletions glpidb/scripts/db_restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
#
# Writter : Boudouma Mohamed Ilies (medilies)
# Github repo: https://github.com/medilies/glpi
# My Linkedin: https://www.linkedin.com/in/medilies/
# -----------------------------------------------------------------------------

#

MYSQL_DATABASE=$(cat /run/secrets/MYSQL_DATABASE)
# MYSQL_USER=$(cat /run/secrets/MYSQL_USER)
MYSQL_ROOT_PASSWORD=$(cat /run/secrets/MYSQL_ROOT_PASSWORD)

echo "Enter the backup file path:"
read -r DATABASE_BACKUP

mysql -uroot -p"$MYSQL_ROOT_PASSWORD" "$MYSQL_DATABASE" <"$DATABASE_BACKUP"
14 changes: 0 additions & 14 deletions glpidb/scripts/files_db_cron.sh

This file was deleted.

5 changes: 5 additions & 0 deletions glpidb/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

/scripts/cron_db_backup.sh

/scripts/db_timezones.sh

0 comments on commit 9fa5a83

Please sign in to comment.