-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
mattermost-restore-application-data.sh
44 lines (34 loc) · 2.19 KB
/
mattermost-restore-application-data.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# # mattermost-restore-application-data.sh Description
# This script is designed to restore the application data.
# 1. **Identify Containers**: Similarly to the database restore script, it identifies the service and backups containers by name.
# 2. **List Application Data Backups**: Displays all available application data backups at the specified backup path.
# 3. **Select Backup**: Asks the user to copy and paste the desired backup name for application data restoration.
# 4. **Stop Service**: Stops the service to prevent any conflicts during the restore process.
# 5. **Restore Application Data**: Removes the current application data and then extracts the selected backup to the appropriate application data path.
# 6. **Start Service**: Restarts the service after the application data has been successfully restored.
# To make the `mattermost-restore-application-data.sh` script executable, run the following command:
# `chmod +x mattermost-restore-application-data.sh`
# By utilizing this script, you can efficiently restore application data from an existing backup while ensuring proper coordination with the running service.
MATTERMOST_CONTAINER=$(docker ps -aqf "name=mattermost-mattermost")
MATTERMOST_BACKUPS_CONTAINER=$(docker ps -aqf "name=mattermost-backups")
BACKUP_PATH="/srv/mattermost-application-data/backups/"
RESTORE_PATH="/mattermost/data/"
BACKUP_PREFIX="mattermost-application-data"
echo "--> All available application data backups:"
for entry in $(docker container exec -it "$MATTERMOST_BACKUPS_CONTAINER" sh -c "ls $BACKUP_PATH")
do
echo "$entry"
done
echo "--> Copy and paste the backup name from the list above to restore application data and press [ENTER]
--> Example: ${BACKUP_PREFIX}-backup-YYYY-MM-DD_hh-mm.tar.gz"
echo -n "--> "
read SELECTED_APPLICATION_BACKUP
echo "--> $SELECTED_APPLICATION_BACKUP was selected"
echo "--> Stopping service..."
docker stop "$MATTERMOST_CONTAINER"
echo "--> Restoring application data..."
docker exec -it "$MATTERMOST_BACKUPS_CONTAINER" sh -c "rm -rf ${RESTORE_PATH}* && tar -zxpf ${BACKUP_PATH}${SELECTED_APPLICATION_BACKUP} -C /"
echo "--> Application data recovery completed..."
echo "--> Starting service..."
docker start "$MATTERMOST_CONTAINER"