biiig wrench

This commit is contained in:
Your Name
2025-05-03 22:58:39 +12:00
parent 107034cf7b
commit 340170b248
51 changed files with 347 additions and 395 deletions

View File

@ -1,36 +1,42 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
# BACKUP SCRIPT
# The backup script is OPTIONAL.
# It is used to backup the service on the server.
# It is called with one argument: the path to the destination backup file.
# If the backup file already exists, the script should exit with a message.
# Nginx Example Backup Script
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
# Get backup file path from first argument
# Load service environment variables
source ./service.env
_check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
die "Backup file path not provided"
_die "Backup file path not provided"
fi
# Check if backup file already exists
if [ -f "$BACKUP_FILE" ]; then
die "Backup file $BACKUP_FILE already exists"
if [ -e "$BACKUP_FILE" ]; then
_die "Backup file $BACKUP_FILE already exists"
fi
# Stop container before backup
_stop_container "$CONTAINER_NAME"
echo "Backing up data for ${CONTAINER_NAME} from ${LOCAL_DATA_FOLDER} to ${BACKUP_FILE}..."
Create backup of data folder
echo "Creating backup of $LOCAL_DATA_FOLDER..."
if ! tar zcvf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER" .; then
_start_container "$CONTAINER_NAME"
die "Failed to create backup"
# Stop container before backup?
# echo "Stopping container ${CONTAINER_NAME} for backup..."
# _stop_container "$CONTAINER_NAME"
# Create backup of data folder
tar -czf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER" .
# Check if backup command was successful
if [ $? -ne 0 ]; then
# Start container again if it was stopped
# echo "Restarting container ${CONTAINER_NAME}..."
# _start_container "$CONTAINER_NAME"
_die "Failed to create backup"
fi
# Start container after backup
_start_container "$CONTAINER_NAME"
# Start container again if it was stopped
# echo "Restarting container ${CONTAINER_NAME}..."
# _start_container "$CONTAINER_NAME"
echo "Backup created successfully: $BACKUP_FILE"
echo "Backup complete: ${BACKUP_FILE}"