added additional sh
This commit is contained in:
parent
25a68b89ba
commit
5a634f2c33
68
readme.md
Normal file
68
readme.md
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
Vikunja Docker Backup and Restore Utilities
|
||||||
|
|
||||||
|
These scripts are designed to simplify the management of your Vikunja Docker installation which uses local volumes (db and files).
|
||||||
|
|
||||||
|
⚠️ PREREQUISITES AND WARNINGS:
|
||||||
|
|
||||||
|
Ensure both scripts (backup.sh and restore.sh) are in the same directory as your docker-compose.yml file.
|
||||||
|
|
||||||
|
Run the following command once to make both scripts executable:
|
||||||
|
|
||||||
|
chmod +x *.sh
|
||||||
|
|
||||||
|
|
||||||
|
The restore script is a DESTRUCTIVE action. It permanently deletes the current db and files directories before restoring data. Use with caution.
|
||||||
|
|
||||||
|
1. Backup Script (backup.sh)
|
||||||
|
|
||||||
|
This script is used to safely create a consistent, compressed snapshot of your application and data.
|
||||||
|
|
||||||
|
Process
|
||||||
|
|
||||||
|
Stops the running Vikunja and MariaDB containers (docker compose down).
|
||||||
|
|
||||||
|
Creates the ./backup directory if it doesn't exist.
|
||||||
|
|
||||||
|
Archives docker-compose.yml, the db/ folder (MariaDB data), and the files/ folder (Vikunja attachments).
|
||||||
|
|
||||||
|
Restarts the services (docker compose up -d).
|
||||||
|
|
||||||
|
Usage
|
||||||
|
|
||||||
|
./backup.sh
|
||||||
|
|
||||||
|
|
||||||
|
Output
|
||||||
|
|
||||||
|
Backups are placed in the ./backup directory with a timestamped filename, e.g., vikunja_backup_YYYYMMDD_HHMMSS.tar.gz.
|
||||||
|
|
||||||
|
2. Restore Script (restore.sh)
|
||||||
|
|
||||||
|
This script is used to revert your application to a previous state from one of your backup archives.
|
||||||
|
|
||||||
|
Process
|
||||||
|
|
||||||
|
Lists all available backup files in the ./backup folder.
|
||||||
|
|
||||||
|
Prompts the user to enter the full filename of the desired backup.
|
||||||
|
|
||||||
|
Stops the running containers.
|
||||||
|
|
||||||
|
DELETES the current db and files data directories.
|
||||||
|
|
||||||
|
Extracts the contents of the selected archive into the current directory.
|
||||||
|
|
||||||
|
Restarts the services.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
|
||||||
|
./restore.sh
|
||||||
|
|
||||||
|
|
||||||
|
The script will guide you through the file selection:
|
||||||
|
|
||||||
|
Available backup archives:
|
||||||
|
1) vikunja_backup_20251128_150000.tar.gz
|
||||||
|
2) vikunja_backup_20251129_201230.tar.gz
|
||||||
|
|
||||||
|
Enter the full filename of the backup you want to restore: vikunja_backup_20251129_201230.tar.gz
|
||||||
68
restore.sh
Normal file
68
restore.sh
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
#!/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 "--------------------------------------------------------"
|
||||||
Loading…
Reference in a new issue