Skip to content

Commit

Permalink
fix typos and scripts issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromeleonard committed Dec 23, 2024
1 parent f6d42ea commit d50b159
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 96 deletions.
10 changes: 5 additions & 5 deletions docs/thehive/installation/deploying-a-cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ For each node in the Cassandra cluster, it's crucial to update the configuration

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

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

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

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

```
Expand All @@ -136,7 +136,7 @@ To initiate the Cassandra service on each node, follow these steps:
!!! Example ""
```bash
root@cassandra:/# nodetool status
Datacenter: dc1
Datacenter: datacenter1
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
Expand Down
117 changes: 58 additions & 59 deletions docs/thehive/operations/backup-restore/backup/docker-compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,20 @@ For example, on the host server, create a folder on a dedicated NFS volume named
#!/bin/bash

## ============================================================
## RESTORE SCRIPT FOR THEHIVE APPLICATION STACK
## BACKUP SCRIPT FOR THEHIVE APPLICATION STACK
## ============================================================
## PURPOSE:
## This script restores a backup of TheHive application stack,
## including its configuration, data, and logs. It is designed to
## recover from backups created using the associated backup script.
## This script creates a backup of TheHive application stack,
## including its configuration, data, and logs. It is designed
## to ensure data is preserved for restoration purposes.
##
## IMPORTANT:
## - A backup is highly recommended before running a restore operation.
## This ensures you can revert to the current state if anything goes wrong.
## - Ensure that the target data folders are empty before running this script.
## Pre-existing files can cause conflicts or data corruption during the restore process.
## - This script must be run with sufficient permissions to overwrite
## application data and modify service configurations.
## - Ensure the backup folder path is correct and contains all required
## files and data.
## - This script must be run with appropriate permissions to read all data
## and write to the backup folders.
## - Ensure sufficient storage is available in the backup location to avoid
## partial or failed backups.
## - Services (Elasticsearch, Cassandra, and TheHive) will be stopped during
## the backup process to ensure data integrity.
##
## DISCLAIMER:
## - Users are strongly advised to test this script in a non-production
Expand All @@ -75,39 +73,40 @@ For example, on the host server, create a folder on a dedicated NFS volume named
##
## USAGE:
## 1. Update the variables at the start of the script to reflect your setup:
## - BACKUP_ROOT_FOLDER: Path to the root directory of your backups.
## - BACKUP_ROOT_FOLDER: Root folder where backups will be stored.
## - BACKUP_TO_RESTORE: Name of the backup folder to restore.
## 2. Run the script using the following command:
## `bash ./scripts/restore.sh`
## `bash ./scripts/backup.sh`
##
## ADDITIONAL RESOURCES:
## Refer to the official documentation for detailed instructions and
## additional information: https://docs.strangebee.com/thehive/operations/backup-restore/
##
## WARNING:
## - This script ensure Nginx, Elasticsearch, Cassandra, and TheHive services are stopped before performing the restore, and then restarts the services.
## - This script will overwrite existing data. Use it with caution.
## - This script stops Nginx, Elasticsearch, Cassandra, and TheHive services,
## performs the backup, and then restarts the services.
## - Do not modify the rest of the script unless necessary.
##
## ============================================================
## DO NOT MODIFY ANYTHING BELOW THIS LINE
## ============================================================

# Display help message
if [[ "$1" == "--help" || "$1" == "-h" ]]
then
echo "Usage: $0 [DOCKER_COMPOSE_PATH] [BACKUP_FOLDER]"
echo "Usage: $0 [BACKUP_ROOT_FOLDER]"
echo
echo "This script restores a backup of application data, including configurations, files, and logs."
echo "This script performs a backup of application data, including configurations, files, and logs."
echo
echo "Options:"
echo " DOCKER_COMPOSE_PATH Optional. Specify the path of the folder with the docker-compose.yml."
echo " If not provided, you will be prompted for a folder, with a default of '.'."
echo " BACKUP_FOLDER Optional. Specify the folder containing the data to restore."
echo " If not provided, you will be prompted for a folder or exit; no default folder is used."
echo " BACKUP_ROOT_FOLDER Optional. Specify the root folder where backups will be stored."
echo " If not provided, you will be prompted for a folder, with a default of './backup'."
echo
echo "Examples:"
echo " $0 /path/to/docker-compose-folder /path/to/backup-folder restores backup stored in the specified folder."
echo " $0 Prompt for docker compose folder and backup folder to restore."
echo " $0 /path/to/docker-compose-folder /path/to/backup Perform backup with specified root folder."
echo " $0 Prompt for docker compose folder and backup root folder."
exit 0
fi

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

if [[ -z "$2" ]]
then
read -p "Enter the backup root folder [default: None]: " BACKUP_FOLDER
[[ -z "${BACKUP_FOLDER}" ]] && echo "No backup folder specified, exiting." && exit 1
read -p "Enter the backup root folder [default: ./backup]: " BACKUP_ROOT_FOLDER
BACKUP_ROOT_FOLDER=${BACKUP_ROOT_FOLDER:-"./backup"}
else
BACKUP_FOLDER="$2"
BACKUP_ROOT_FOLDER="$2"
fi

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


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


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

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

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

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

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

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

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

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

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

# Copy Nginx certificates
echo "Restoring Nginx data and configuration..."
rsync -a ${BACKUP_FOLDER}/nginx/ ${DOCKER_COMPOSE_PATH}/nginx ||
{ echo " Nginx configuration and certificates restore failed"; exit 1; }
rsync -a ${BACKUP_FOLDER}/certificates/ ${DOCKER_COMPOSE_PATH}/certificates ||
{ echo " certificates restore failed"; exit 1; }
## Copy Nginx certificates
echo "Starting backup of Nginx and certificates..."
rsync -aW --no-compress ${DOCKER_COMPOSE_PATH}/nginx/ ${BACKUP_FOLDER}/nginx || { echo " Backup of Nginx failed"; exit 1; }
rsync -aW --no-compress ${DOCKER_COMPOSE_PATH}/certificates/ ${BACKUP_FOLDER}/certificates || { echo " Backup of Nginx and certificates failed"; exit 1; }
echo "Backup of certificates completed."

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

### Restart the services

!!! Example ""

```bash
docker compose up -d
echo "Backup process completed at: $(date)"
```

---
Expand Down
104 changes: 72 additions & 32 deletions docs/thehive/operations/backup-restore/restore/docker-compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Ensure that the target data folders are empty before running this script. Indeed

```bash
#!/bin/bash

## ============================================================
## RESTORE SCRIPT FOR THEHIVE APPLICATION STACK
## ============================================================
Expand Down Expand Up @@ -61,38 +62,70 @@ Ensure that the target data folders are empty before running this script. Indeed
##
## ADDITIONAL RESOURCES:
## Refer to the official documentation for detailed instructions and
## additional information: https://docs.strangebee.com/thehive/operations/backup-restore/restore/docker-compose/
## additional information: https://docs.strangebee.com/thehive/operations/backup-restore/
##
## WARNING:
## - This script ensure Nginx, Elasticsearch, Cassandra, and TheHive services are stopped before performing the restore, and then restarts the services.
## - This script will overwrite existing data. Use it with caution.
## - Do not modify the rest of the script unless necessary.
##
## ============================================================

## ============================================================
## USER-CONFIGURABLE VARIABLES
## ============================================================
##
## Update the following variables to match your environment
## Path to the docker-compose.yml file
DOCKER_COMPOSE_PATH="./"
## Path to backup folder
BACKUP_ROOT_FOLDER="/opt/backups"
## Name of the folder containing the backup to restore
BACKUP_TO_RESTORE="14122024-1044-0000"
## ============================================================
## DO NOT MODIFY ANYTHING BELOW THIS LINE
## ============================================================

# Check backup backup folder exists
BACKUP_FOLDER="${BACKUP_ROOT_FOLDER}/${BACKUP_TO_RESTORE}"
[[ -d ${BACKUP_FOLDER} ]] || { echo "Backup folder not found"; exit 1; }


# Define the log file and start logging
# Display help message
if [[ "$1" == "--help" || "$1" == "-h" ]]
then
echo "Usage: $0 [DOCKER_COMPOSE_PATH] [BACKUP_FOLDER]"
echo
echo "This script restores a backup of application data, including configurations, files, and logs."
echo
echo "Options:"
echo " DOCKER_COMPOSE_PATH Optional. Specify the path of the folder with the docker-compose.yml."
echo " If not provided, you will be prompted for a folder, with a default of '.'."
echo " BACKUP_FOLDER Optional. Specify the folder containing the data to restore."
echo " If not provided, you will be prompted for a folder or exit; no default folder is used."
echo
echo "Examples:"
echo " $0 /path/to/docker-compose-folder /path/to/backup-folder restores backup stored in the specified folder."
echo " $0 Prompt for docker compose folder and backup folder to restore."
exit 0
fi

## Checks if the first argument is provided.
## If it is, the script uses it as the value for BACKUP_ROOT_FOLDER
## If no argument is passed, the script prompts the user to enter a value
##
if [[ -z "$1" ]]
then
read -p "Enter the folder path including your docker compose file [default: ./]: " DOCKER_COMPOSE_PATH
DOCKER_COMPOSE_PATH=${DOCKER_COMPOSE_PATH:-"."}
else
DOCKER_COMPOSE_PATH="$1"
fi

if [[ -e "${DOCKER_COMPOSE_PATH}/docker-compose.yml" ]]
then
echo "Path to your docker compose file: ${DOCKER_COMPOSE_PATH}/docker-compose.yml"
else
{ echo "Docker compose file not found in ${DOCKER_COMPOSE_PATH}"; exit 1; }
fi


if [[ -z "$2" ]]
then
read -p "Enter the backup root folder [default: None]: " BACKUP_FOLDER
[[ -z "${BACKUP_FOLDER}" ]] && echo "No backup folder specified, exiting." && exit 1
else
BACKUP_FOLDER="$2"
fi

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


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

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


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

# Copy Casssandra data
echo "Restoring Cassandra data ..."
rsync -aW --no-compress ${BACKUP_FOLDER}/cassandra/ ${DOCKER_COMPOSE_PATH}/cassandra || { echo "Cassandra data restore failed"; exit 1; }


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

# Copy Nginx certificates
echo "Restoring Nginx data and configuration..."
rsync -a ${BACKUP_FOLDER}/nginx/ ${DOCKER_COMPOSE_PATH}/nginx || { echo " Nginx configuration and certificates restore failed"; exit 1; }
rsync -a ${BACKUP_FOLDER}/certificates/ ${DOCKER_COMPOSE_PATH}/certificates || { echo " certificates restore failed"; exit 1; }
rsync -a ${BACKUP_FOLDER}/nginx/ ${DOCKER_COMPOSE_PATH}/nginx ||
{ echo " Nginx configuration and certificates restore failed"; exit 1; }
rsync -a ${BACKUP_FOLDER}/certificates/ ${DOCKER_COMPOSE_PATH}/certificates ||
{ echo " certificates restore failed"; exit 1; }

## Restart services
echo "Restarting services..."
docker compose up -d -f ${DOCKER_COMPOSE_PATH}/docker-compose.yml

echo "Restoration process completed at: $(date)"
```


### Restart all services

!!! Example ""

```bash
docker compose up -d
```
The script above restarts all services with the command line `docker compose up -d -f ${DOCKER_COMPOSE_PATH}/docker-compose.yml`.

0 comments on commit d50b159

Please sign in to comment.