All checks were successful
Test and Publish Templates / test-and-publish (push) Successful in 42s
44 lines
1.5 KiB
Bash
Executable File
44 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# shellcheck disable=SC1091
|
|
source "${AGENT_PATH}/common.sh"
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "${SCRIPT_DIR}/_volumes.sh"
|
|
_check_required_env_vars "CONTAINER_NAME" "DATA_PATH" "DB_NAME" "DB_USER"
|
|
|
|
# Export variables for docker compose
|
|
export CONTAINER_NAME DATA_PATH HTTP_PORT PUID PGID TZ IMAGE_TAG DB_NAME DB_USER DB_PASS
|
|
|
|
cd "$SCRIPT_DIR"
|
|
|
|
# Stop and remove containers before restore
|
|
docker compose down
|
|
|
|
# Restore files using dropshell's restore system
|
|
# shellcheck disable=SC2046
|
|
restore_items $(get_wikijs_volumes) || _die "Failed to restore data from backup file"
|
|
|
|
# Start database container only
|
|
docker compose up -d db
|
|
echo "Waiting for database to be ready..."
|
|
sleep 5
|
|
|
|
# Restore database if dump exists
|
|
if [ -f "${DATA_PATH}/database.sql" ]; then
|
|
echo "Restoring PostgreSQL database..."
|
|
# Drop and recreate database
|
|
docker exec ${CONTAINER_NAME}_db psql -U "$DB_USER" -d postgres -c "DROP DATABASE IF EXISTS ${DB_NAME};"
|
|
docker exec ${CONTAINER_NAME}_db psql -U "$DB_USER" -d postgres -c "CREATE DATABASE ${DB_NAME};"
|
|
# Restore from dump
|
|
docker exec -i ${CONTAINER_NAME}_db psql -U "$DB_USER" -d "$DB_NAME" < "${DATA_PATH}/database.sql" || _die "Failed to restore database"
|
|
# Clean up dump file
|
|
rm -f "${DATA_PATH}/database.sql"
|
|
echo "Database restored successfully"
|
|
else
|
|
echo "Warning: No database dump found in backup"
|
|
fi
|
|
|
|
# Start all containers
|
|
docker compose up -d
|
|
|
|
echo "Restore complete! Service is running."
|