2025-05-03 21:53:11 +12:00

41 lines
945 B
Bash

#!/bin/bash
# BACKUP SCRIPT
# The backup script is OPTIONAL.
# It is used to backup the service on the server.
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"