Skip to content

Commit d50b159

Browse files
committed
fix typos and scripts issues
1 parent f6d42ea commit d50b159

File tree

3 files changed

+135
-96
lines changed

3 files changed

+135
-96
lines changed

docs/thehive/installation/deploying-a-cluster.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ For each node in the Cassandra cluster, it's crucial to update the configuration
6262

6363
```yaml title="/etc/cassandra/cassandra.yaml" hl_lines="13"
6464
cluster_name: 'thp'
65-
num_tokens: 16
65+
num_tokens: 4
6666
authenticator: PasswordAuthenticator
6767
authorizer: CassandraAuthorizer
6868
role_manager: CassandraRoleManager
@@ -107,15 +107,15 @@ For each node in the Cassandra cluster, it's crucial to update the configuration
107107

108108
```yaml title="cassandra-rackdc.properties" hl_lines="13"
109109
## On node1, edit /etc/cassandra/cassandra-rackdc.properties and add the following conf
110-
dc=dc1
110+
dc=datacenter1
111111
rack=rack1
112112

113113
## On node2, edit /etc/cassandra/cassandra-rackdc.properties and add the following conf
114-
dc=dc1
114+
dc=datacenter1
115115
rack=rack2
116116

117117
## On node3, edit /etc/cassandra/cassandra-rackdc.properties and add the following conf
118-
dc=dc1
118+
dc=datacenter1
119119
rack=rack3
120120

121121
```
@@ -136,7 +136,7 @@ To initiate the Cassandra service on each node, follow these steps:
136136
!!! Example ""
137137
```bash
138138
root@cassandra:/# nodetool status
139-
Datacenter: dc1
139+
Datacenter: datacenter1
140140
===============
141141
Status=Up/Down
142142
|/ State=Normal/Leaving/Joining/Moving

docs/thehive/operations/backup-restore/backup/docker-compose.md

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,20 @@ For example, on the host server, create a folder on a dedicated NFS volume named
4848
#!/bin/bash
4949

5050
## ============================================================
51-
## RESTORE SCRIPT FOR THEHIVE APPLICATION STACK
51+
## BACKUP SCRIPT FOR THEHIVE APPLICATION STACK
5252
## ============================================================
5353
## PURPOSE:
54-
## This script restores a backup of TheHive application stack,
55-
## including its configuration, data, and logs. It is designed to
56-
## recover from backups created using the associated backup script.
54+
## This script creates a backup of TheHive application stack,
55+
## including its configuration, data, and logs. It is designed
56+
## to ensure data is preserved for restoration purposes.
5757
##
5858
## IMPORTANT:
59-
## - A backup is highly recommended before running a restore operation.
60-
## This ensures you can revert to the current state if anything goes wrong.
61-
## - Ensure that the target data folders are empty before running this script.
62-
## Pre-existing files can cause conflicts or data corruption during the restore process.
63-
## - This script must be run with sufficient permissions to overwrite
64-
## application data and modify service configurations.
65-
## - Ensure the backup folder path is correct and contains all required
66-
## files and data.
59+
## - This script must be run with appropriate permissions to read all data
60+
## and write to the backup folders.
61+
## - Ensure sufficient storage is available in the backup location to avoid
62+
## partial or failed backups.
63+
## - Services (Elasticsearch, Cassandra, and TheHive) will be stopped during
64+
## the backup process to ensure data integrity.
6765
##
6866
## DISCLAIMER:
6967
## - Users are strongly advised to test this script in a non-production
@@ -75,39 +73,40 @@ For example, on the host server, create a folder on a dedicated NFS volume named
7573
##
7674
## USAGE:
7775
## 1. Update the variables at the start of the script to reflect your setup:
78-
## - BACKUP_ROOT_FOLDER: Path to the root directory of your backups.
76+
## - BACKUP_ROOT_FOLDER: Root folder where backups will be stored.
7977
## - BACKUP_TO_RESTORE: Name of the backup folder to restore.
8078
## 2. Run the script using the following command:
81-
## `bash ./scripts/restore.sh`
79+
## `bash ./scripts/backup.sh`
8280
##
8381
## ADDITIONAL RESOURCES:
8482
## Refer to the official documentation for detailed instructions and
8583
## additional information: https://docs.strangebee.com/thehive/operations/backup-restore/
8684
##
8785
## WARNING:
88-
## - This script ensure Nginx, Elasticsearch, Cassandra, and TheHive services are stopped before performing the restore, and then restarts the services.
89-
## - This script will overwrite existing data. Use it with caution.
86+
## - This script stops Nginx, Elasticsearch, Cassandra, and TheHive services,
87+
## performs the backup, and then restarts the services.
9088
## - Do not modify the rest of the script unless necessary.
9189
##
9290
## ============================================================
9391
## DO NOT MODIFY ANYTHING BELOW THIS LINE
9492
## ============================================================
93+
9594
# Display help message
9695
if [[ "$1" == "--help" || "$1" == "-h" ]]
9796
then
98-
echo "Usage: $0 [DOCKER_COMPOSE_PATH] [BACKUP_FOLDER]"
97+
echo "Usage: $0 [BACKUP_ROOT_FOLDER]"
9998
echo
100-
echo "This script restores a backup of application data, including configurations, files, and logs."
99+
echo "This script performs a backup of application data, including configurations, files, and logs."
101100
echo
102101
echo "Options:"
103102
echo " DOCKER_COMPOSE_PATH Optional. Specify the path of the folder with the docker-compose.yml."
104103
echo " If not provided, you will be prompted for a folder, with a default of '.'."
105-
echo " BACKUP_FOLDER Optional. Specify the folder containing the data to restore."
106-
echo " If not provided, you will be prompted for a folder or exit; no default folder is used."
104+
echo " BACKUP_ROOT_FOLDER Optional. Specify the root folder where backups will be stored."
105+
echo " If not provided, you will be prompted for a folder, with a default of './backup'."
107106
echo
108107
echo "Examples:"
109-
echo " $0 /path/to/docker-compose-folder /path/to/backup-folder restores backup stored in the specified folder."
110-
echo " $0 Prompt for docker compose folder and backup folder to restore."
108+
echo " $0 /path/to/docker-compose-folder /path/to/backup Perform backup with specified root folder."
109+
echo " $0 Prompt for docker compose folder and backup root folder."
111110
exit 0
112111
fi
113112

@@ -133,62 +132,62 @@ For example, on the host server, create a folder on a dedicated NFS volume named
133132

134133
if [[ -z "$2" ]]
135134
then
136-
read -p "Enter the backup root folder [default: None]: " BACKUP_FOLDER
137-
[[ -z "${BACKUP_FOLDER}" ]] && echo "No backup folder specified, exiting." && exit 1
135+
read -p "Enter the backup root folder [default: ./backup]: " BACKUP_ROOT_FOLDER
136+
BACKUP_ROOT_FOLDER=${BACKUP_ROOT_FOLDER:-"./backup"}
138137
else
139-
BACKUP_FOLDER="$2"
138+
BACKUP_ROOT_FOLDER="$2"
140139
fi
141140

142-
## Check if the backup folder to restore exists, else exit
143-
[[ -d ${BACKUP_FOLDER} ]] || { echo "Backup folder not found, exiting"; exit 1; }
144-
145141

146-
# Define the log file and start logging. Log file is stored in the current folder
147142
DATE="$(date +"%Y%m%d-%H%M%z" | sed 's/+/-/')"
148-
LOG_FILE="./restore_log_${DATE}.log"
149-
exec &> >(tee -a "$LOG_FILE")
143+
BACKUP_FOLDER="${BACKUP_ROOT_FOLDER}/${DATE}"
144+
150145

151-
# Log the start time
152-
echo "Restoration process started at: $(date)"
146+
## Stop services
147+
docker compose -f ${DOCKER_COMPOSE_PATH}/docker-compose.yml stop
153148

154-
## Exit if docker compose is running
155-
docker compose ps | grep -q "Up" && { echo "Docker Compose services are running. Exiting. Stop services and remove data before retoring data"; exit 1; }
149+
## Create the backup directory
150+
mkdir -p "${BACKUP_FOLDER}" || { echo "Creating backup folder failed"; exit 1; }
151+
echo "Created backup folder: ${BACKUP_FOLDER}"
156152

153+
## Define the log file and start logging
154+
LOG_FILE="${BACKUP_ROOT_FOLDER}/backup_log_${DATE}.log"
155+
exec &> >(tee -a "$LOG_FILE")
157156

158-
# Copy TheHive data
159-
echo "Restoring TheHive data and configuration..."
160-
rsync -aW --no-compress ${BACKUP_FOLDER}/thehive/ ${DOCKER_COMPOSE_PATH}/thehive || { echo "TheHive config restore failed"; exit 1; }
161157

162-
# Copy Cortex data
163-
echo "Restoring Cortex data and configuration..."
164-
rsync -aW --no-compress ${BACKUP_FOLDER}/cortex/ ${DOCKER_COMPOSE_PATH}/cortex || { echo "Cortex config restore failed"; exit 1; }
165158

166-
# Copy Casssandra data
167-
echo "Restoring Cassandra data ..."
168-
rsync -aW --no-compress ${BACKUP_FOLDER}/cassandra/ ${DOCKER_COMPOSE_PATH}/cassandra || { echo "Cassandra data restore failed"; exit 1; }
159+
## Prepare folders tree
160+
mkdir -p ${BACKUP_FOLDER}/{thehive,cassandra,elasticsearch,nginx,certificates}
161+
echo "Created folder structure under ${BACKUP_FOLDER}"
169162

163+
## Copy TheHive data
164+
echo "Starting TheHive backup..."
165+
rsync -aW --no-compress ${DOCKER_COMPOSE_PATH}/thehive/ ${BACKUP_FOLDER}/thehive || { echo "TheHive backup failed"; exit 1; }
166+
echo "TheHive backup completed."
170167

171-
# Copy Elasticsearch data
172-
echo "Restoring Elasticsearch data ..."
173-
rsync -aW --no-compress ${BACKUP_FOLDER}/elasticsearch/ ${DOCKER_COMPOSE_PATH}/elasticsearch || { echo "Elasticsearch data restore failed"; exit 1; }
168+
## Copy Casssandra data
169+
echo "Starting Cassandra backup..."
170+
rsync -aW --no-compress ${DOCKER_COMPOSE_PATH}/cassandra/ ${BACKUP_FOLDER}/cassandra || { echo "Cassandra backup failed"; exit 1; }
171+
echo "Cassandra backup completed."
174172

173+
## Copy Elasticsearch data
174+
echo "Starting Elasticsearch backup..."
175+
rsync -aW --no-compress ${DOCKER_COMPOSE_PATH}/elasticsearch/ ${BACKUP_FOLDER}/elasticsearch || { echo "Elasticsearch config backup failed"; exit 1; }
176+
echo "Elasticsearch backup completed."
175177

176-
# Copy Nginx certificates
177-
echo "Restoring Nginx data and configuration..."
178-
rsync -a ${BACKUP_FOLDER}/nginx/ ${DOCKER_COMPOSE_PATH}/nginx ||
179-
{ echo " Nginx configuration and certificates restore failed"; exit 1; }
180-
rsync -a ${BACKUP_FOLDER}/certificates/ ${DOCKER_COMPOSE_PATH}/certificates ||
181-
{ echo " certificates restore failed"; exit 1; }
178+
## Copy Nginx certificates
179+
echo "Starting backup of Nginx and certificates..."
180+
rsync -aW --no-compress ${DOCKER_COMPOSE_PATH}/nginx/ ${BACKUP_FOLDER}/nginx || { echo " Backup of Nginx failed"; exit 1; }
181+
rsync -aW --no-compress ${DOCKER_COMPOSE_PATH}/certificates/ ${BACKUP_FOLDER}/certificates || { echo " Backup of Nginx and certificates failed"; exit 1; }
182+
echo "Backup of certificates completed."
182183

183-
echo "Restoration process completed at: $(date)"
184-
```
184+
## Restart services
185+
echo "Restarting services..."
186+
docker compose up -d -f ${DOCKER_COMPOSE_PATH}/docker-compose.yml
185187

186-
### Restart the services
187188

188-
!!! Example ""
189189

190-
```bash
191-
docker compose up -d
190+
echo "Backup process completed at: $(date)"
192191
```
193192

194193
---

docs/thehive/operations/backup-restore/restore/docker-compose.md

Lines changed: 72 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Ensure that the target data folders are empty before running this script. Indeed
2626

2727
```bash
2828
#!/bin/bash
29+
2930
## ============================================================
3031
## RESTORE SCRIPT FOR THEHIVE APPLICATION STACK
3132
## ============================================================
@@ -61,38 +62,70 @@ Ensure that the target data folders are empty before running this script. Indeed
6162
##
6263
## ADDITIONAL RESOURCES:
6364
## Refer to the official documentation for detailed instructions and
64-
## additional information: https://docs.strangebee.com/thehive/operations/backup-restore/restore/docker-compose/
65+
## additional information: https://docs.strangebee.com/thehive/operations/backup-restore/
6566
##
6667
## WARNING:
6768
## - This script ensure Nginx, Elasticsearch, Cassandra, and TheHive services are stopped before performing the restore, and then restarts the services.
6869
## - This script will overwrite existing data. Use it with caution.
6970
## - Do not modify the rest of the script unless necessary.
7071
##
7172
## ============================================================
72-
73-
## ============================================================
74-
## USER-CONFIGURABLE VARIABLES
75-
## ============================================================
76-
##
77-
## Update the following variables to match your environment
78-
## Path to the docker-compose.yml file
79-
DOCKER_COMPOSE_PATH="./"
80-
## Path to backup folder
81-
BACKUP_ROOT_FOLDER="/opt/backups"
82-
## Name of the folder containing the backup to restore
83-
BACKUP_TO_RESTORE="14122024-1044-0000"
84-
## ============================================================
8573
## DO NOT MODIFY ANYTHING BELOW THIS LINE
8674
## ============================================================
87-
88-
# Check backup backup folder exists
89-
BACKUP_FOLDER="${BACKUP_ROOT_FOLDER}/${BACKUP_TO_RESTORE}"
90-
[[ -d ${BACKUP_FOLDER} ]] || { echo "Backup folder not found"; exit 1; }
91-
92-
93-
# Define the log file and start logging
75+
# Display help message
76+
if [[ "$1" == "--help" || "$1" == "-h" ]]
77+
then
78+
echo "Usage: $0 [DOCKER_COMPOSE_PATH] [BACKUP_FOLDER]"
79+
echo
80+
echo "This script restores a backup of application data, including configurations, files, and logs."
81+
echo
82+
echo "Options:"
83+
echo " DOCKER_COMPOSE_PATH Optional. Specify the path of the folder with the docker-compose.yml."
84+
echo " If not provided, you will be prompted for a folder, with a default of '.'."
85+
echo " BACKUP_FOLDER Optional. Specify the folder containing the data to restore."
86+
echo " If not provided, you will be prompted for a folder or exit; no default folder is used."
87+
echo
88+
echo "Examples:"
89+
echo " $0 /path/to/docker-compose-folder /path/to/backup-folder restores backup stored in the specified folder."
90+
echo " $0 Prompt for docker compose folder and backup folder to restore."
91+
exit 0
92+
fi
93+
94+
## Checks if the first argument is provided.
95+
## If it is, the script uses it as the value for BACKUP_ROOT_FOLDER
96+
## If no argument is passed, the script prompts the user to enter a value
97+
##
98+
if [[ -z "$1" ]]
99+
then
100+
read -p "Enter the folder path including your docker compose file [default: ./]: " DOCKER_COMPOSE_PATH
101+
DOCKER_COMPOSE_PATH=${DOCKER_COMPOSE_PATH:-"."}
102+
else
103+
DOCKER_COMPOSE_PATH="$1"
104+
fi
105+
106+
if [[ -e "${DOCKER_COMPOSE_PATH}/docker-compose.yml" ]]
107+
then
108+
echo "Path to your docker compose file: ${DOCKER_COMPOSE_PATH}/docker-compose.yml"
109+
else
110+
{ echo "Docker compose file not found in ${DOCKER_COMPOSE_PATH}"; exit 1; }
111+
fi
112+
113+
114+
if [[ -z "$2" ]]
115+
then
116+
read -p "Enter the backup root folder [default: None]: " BACKUP_FOLDER
117+
[[ -z "${BACKUP_FOLDER}" ]] && echo "No backup folder specified, exiting." && exit 1
118+
else
119+
BACKUP_FOLDER="$2"
120+
fi
121+
122+
## Check if the backup folder to restore exists, else exit
123+
[[ -d ${BACKUP_FOLDER} ]] || { echo "Backup folder not found, exiting"; exit 1; }
124+
125+
126+
# Define the log file and start logging. Log file is stored in the current folder
94127
DATE="$(date +"%Y%m%d-%H%M%z" | sed 's/+/-/')"
95-
LOG_FILE="${BACKUP_ROOT_FOLDER}/restore_log_${DATE}.log"
128+
LOG_FILE="./restore_log_${DATE}.log"
96129
exec &> >(tee -a "$LOG_FILE")
97130

98131
# Log the start time
@@ -102,9 +135,13 @@ Ensure that the target data folders are empty before running this script. Indeed
102135
docker compose ps | grep -q "Up" && { echo "Docker Compose services are running. Exiting. Stop services and remove data before retoring data"; exit 1; }
103136

104137

105-
# Copy Cortex data
106-
echo "Restoring Cortex data and configuration..."
107-
rsync -aW --no-compress ${BACKUP_FOLDER}/cortex/ ${DOCKER_COMPOSE_PATH}/cortex || { echo "Cortex config restore failed"; exit 1; }
138+
# Copy TheHive data
139+
echo "Restoring TheHive data and configuration..."
140+
rsync -aW --no-compress ${BACKUP_FOLDER}/thehive/ ${DOCKER_COMPOSE_PATH}/thehive || { echo "TheHive config restore failed"; exit 1; }
141+
142+
# Copy Casssandra data
143+
echo "Restoring Cassandra data ..."
144+
rsync -aW --no-compress ${BACKUP_FOLDER}/cassandra/ ${DOCKER_COMPOSE_PATH}/cassandra || { echo "Cassandra data restore failed"; exit 1; }
108145

109146

110147
# Copy Elasticsearch data
@@ -114,16 +151,19 @@ Ensure that the target data folders are empty before running this script. Indeed
114151

115152
# Copy Nginx certificates
116153
echo "Restoring Nginx data and configuration..."
117-
rsync -a ${BACKUP_FOLDER}/nginx/ ${DOCKER_COMPOSE_PATH}/nginx || { echo " Nginx configuration and certificates restore failed"; exit 1; }
118-
rsync -a ${BACKUP_FOLDER}/certificates/ ${DOCKER_COMPOSE_PATH}/certificates || { echo " certificates restore failed"; exit 1; }
154+
rsync -a ${BACKUP_FOLDER}/nginx/ ${DOCKER_COMPOSE_PATH}/nginx ||
155+
{ echo " Nginx configuration and certificates restore failed"; exit 1; }
156+
rsync -a ${BACKUP_FOLDER}/certificates/ ${DOCKER_COMPOSE_PATH}/certificates ||
157+
{ echo " certificates restore failed"; exit 1; }
158+
159+
## Restart services
160+
echo "Restarting services..."
161+
docker compose up -d -f ${DOCKER_COMPOSE_PATH}/docker-compose.yml
162+
119163
echo "Restoration process completed at: $(date)"
120164
```
121165

122166

123167
### Restart all services
124168

125-
!!! Example ""
126-
127-
```bash
128-
docker compose up -d
129-
```
169+
The script above restarts all services with the command line `docker compose up -d -f ${DOCKER_COMPOSE_PATH}/docker-compose.yml`.

0 commit comments

Comments
 (0)