added backup script
This commit is contained in:
parent
c612802a56
commit
25a68b89ba
45
backup.sh
Executable file
45
backup.sh
Executable file
|
|
@ -0,0 +1,45 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# --- Configuration ---
|
||||||
|
BACKUP_DIR="./backup"
|
||||||
|
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
||||||
|
BACKUP_FILENAME="vikunja_backup_${TIMESTAMP}.tar.gz"
|
||||||
|
|
||||||
|
# Data directories and files to include in the backup
|
||||||
|
# This includes the MariaDB volume, the Vikunja files volume, and the docker-compose.yml
|
||||||
|
FILES_TO_BACKUP="docker-compose.yml db files"
|
||||||
|
|
||||||
|
# Exit immediately if a command exits with a non-zero status
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "Starting Vikunja backup process at ${TIMESTAMP}..."
|
||||||
|
|
||||||
|
# 1. Stop all services (keeping volumes intact)
|
||||||
|
echo "1. Shutting down Docker services (docker compose down)..."
|
||||||
|
# Use '-v' to remove volumes if needed, but here we just want to stop containers
|
||||||
|
docker compose down
|
||||||
|
|
||||||
|
# 2. Ensure the backup directory exists
|
||||||
|
echo "2. Creating backup directory: ${BACKUP_DIR}"
|
||||||
|
mkdir -p "${BACKUP_DIR}"
|
||||||
|
|
||||||
|
# 3. Create the timestamped tar archive
|
||||||
|
echo "3. Creating archive: ${BACKUP_DIR}/${BACKUP_FILENAME}"
|
||||||
|
# 'tar' command explanation:
|
||||||
|
# - c: Create a new archive
|
||||||
|
# - z: Compress the archive using gzip
|
||||||
|
# - v: Verbose output (show files being added)
|
||||||
|
# - f: Specify the filename
|
||||||
|
# Note: The data directories (db and files) and the compose file are included.
|
||||||
|
tar -czvf "${BACKUP_DIR}/${BACKUP_FILENAME}" ${FILES_TO_BACKUP}
|
||||||
|
|
||||||
|
# 4. Restart the services
|
||||||
|
echo "4. Bringing Docker services back up (docker compose up -d)..."
|
||||||
|
docker compose up -d
|
||||||
|
|
||||||
|
# 5. Completion message
|
||||||
|
echo "--------------------------------------------------------"
|
||||||
|
echo "✅ Backup successfully completed!"
|
||||||
|
echo "Archive saved to: ${BACKUP_DIR}/${BACKUP_FILENAME}"
|
||||||
|
echo "Vikunja services are now running again."
|
||||||
|
echo "--------------------------------------------------------"
|
||||||
Loading…
Reference in a new issue