2025-05-03 16:34:54 +12:00

43 lines
1.1 KiB
Bash

#!/bin/bash
# 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.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
# HOT backup is fine for simple-object-storage
# Get backup file path from first argument
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
die "Backup file path not provided"
fi
TEMP_DIR=$2
if [ -z "$TEMP_DIR" ]; then
die "Temporary directory not provided"
fi
# Check if backup file already exists
if [ -f "$BACKUP_FILE" ]; then
die "Backup file $BACKUP_FILE already exists"
fi
# Create backup of data folder
echo "Creating backup of $VOLUME_NAME..."
docker run --rm -v ${VOLUME_NAME}:/data -v ${TEMP_DIR}:/tempdir alpine sh -c "\
tar zcvf /tempdir/backup.tar.gz -C /data ."
cp ${TEMP_DIR}/backup.tar.gz $BACKUP_FILE
# dropshell cleans up temp dir after script finishes
echo "Backup created successfully: $BACKUP_FILE"