Vikunja/restore.sh

68 lines
2.1 KiB
Bash
Raw Permalink Normal View History

2025-11-29 19:14:25 +00:00
#!/bin/bash
# --- Configuration ---
BACKUP_DIR="./backup"
# Exit immediately if a command exits with a non-zero status
set -e
echo "Starting Vikunja restore process."
# 1. Check for backups and display options
echo "Checking for available backups..."
if [ ! -d "$BACKUP_DIR" ] || [ -z "$(find "$BACKUP_DIR" -maxdepth 1 -name "*.tar.gz" -print -quit 2>/dev/null)" ]; then
echo "❌ Error: No backup files (*.tar.gz) found in '${BACKUP_DIR}'. Aborting."
exit 1
fi
echo "Available backup archives in ${BACKUP_DIR}:"
find "$BACKUP_DIR" -maxdepth 1 -name "*.tar.gz" -printf "%f\n" | nl -w 3 -s ') '
echo
# 2. Get user input for which file to restore
while true; do
read -r -p "Enter the full filename of the backup you want to restore: " ARCHIVE_NAME
ARCHIVE_PATH="${BACKUP_DIR}/${ARCHIVE_NAME}"
if [ -f "$ARCHIVE_PATH" ]; then
break
else
echo "File not found: ${ARCHIVE_PATH}. Please ensure the name is correct. (Ctrl+C to exit)."
fi
done
echo "Attempting to restore from: ${ARCHIVE_PATH}"
# 3. Stop running services
echo "1. Shutting down Docker services (docker compose down)..."
docker compose down
# 4. Clean up current data (DANGEROUS STEP: BE SURE BEFORE RUNNING)
echo "2. Deleting current data directories to prepare for restoration..."
if [ -d "db" ]; then
echo " - Removing current 'db' directory."
rm -rf db
fi
if [ -d "files" ]; then
echo " - Removing current 'files' directory."
rm -rf files
fi
if [ -f "docker-compose.yml" ]; then
echo " - NOTE: Overwriting current 'docker-compose.yml'."
fi
# 5. Extract the backup
echo "3. Extracting data from archive..."
# This extracts db/, files/, and docker-compose.yml into the current directory
tar -xzvf "$ARCHIVE_PATH"
# 6. Restart the services
echo "4. Bringing Docker services back up (docker compose up -d)..."
docker compose up -d
# 7. Completion message
echo "--------------------------------------------------------"
echo "✅ Restoration successfully completed!"
echo "Vikunja services are now running again with data from ${ARCHIVE_NAME}."
echo "--------------------------------------------------------"