mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 00:00:13 -08:00
feat: Add base HTML template and implement dashboard, logs, and service views
- Created a base HTML template for consistent layout across pages. - Developed a dashboard page to display backup service metrics and statuses. - Implemented a log viewer for detailed log file inspection. - Added error handling page for better user experience during failures. - Introduced service detail page to show specific service metrics and actions. - Enhanced log filtering and viewing capabilities. - Integrated auto-refresh functionality for real-time updates on metrics. - Created integration and unit test scripts for backup metrics functionality.
This commit is contained in:
@@ -9,11 +9,32 @@
|
||||
# Set up error handling
|
||||
set -e
|
||||
|
||||
# Load the unified backup metrics library
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
LIB_DIR="$(dirname "$SCRIPT_DIR")/lib"
|
||||
if [[ -f "$LIB_DIR/unified-backup-metrics.sh" ]]; then
|
||||
# shellcheck source=../lib/unified-backup-metrics.sh
|
||||
source "$LIB_DIR/unified-backup-metrics.sh"
|
||||
METRICS_ENABLED=true
|
||||
else
|
||||
echo "Warning: Unified backup metrics library not found at $LIB_DIR/unified-backup-metrics.sh"
|
||||
METRICS_ENABLED=false
|
||||
fi
|
||||
|
||||
# Function to ensure server is unpaused even if script fails
|
||||
cleanup() {
|
||||
local exit_code=$?
|
||||
echo "Running cleanup..."
|
||||
|
||||
# Finalize metrics if enabled
|
||||
if [[ "$METRICS_ENABLED" == "true" ]]; then
|
||||
if [[ $exit_code -eq 0 ]]; then
|
||||
metrics_backup_complete "success" "Immich backup completed successfully"
|
||||
else
|
||||
metrics_backup_complete "failed" "Immich backup failed during execution"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check if immich_server is paused and unpause it if needed
|
||||
if [ "${IMMICH_SERVER_RUNNING:-true}" = true ] && docker inspect --format='{{.State.Status}}' immich_server 2>/dev/null | grep -q "paused"; then
|
||||
echo "Unpausing immich_server container during cleanup..."
|
||||
@@ -322,6 +343,12 @@ fi
|
||||
# Send start notification
|
||||
send_notification "🚀 Immich Backup Started" "Starting complete backup of Immich database and uploads directory" "info"
|
||||
|
||||
# Initialize backup metrics if enabled
|
||||
if [[ "$METRICS_ENABLED" == "true" ]]; then
|
||||
metrics_backup_start "immich" "Immich photo management system backup"
|
||||
metrics_update_status "running" "Preparing backup environment"
|
||||
fi
|
||||
|
||||
# Check if the Immich server container exists and is running
|
||||
log_status "Checking immich_server container status..."
|
||||
if docker ps -q --filter "name=immich_server" | grep -q .; then
|
||||
@@ -345,6 +372,12 @@ fi
|
||||
|
||||
echo ""
|
||||
echo "=== PHASE 1: DATABASE BACKUP ==="
|
||||
|
||||
# Update metrics for database backup phase
|
||||
if [[ "$METRICS_ENABLED" == "true" ]]; then
|
||||
metrics_update_status "running" "Starting database backup"
|
||||
fi
|
||||
|
||||
log_message "Taking database backup using pg_dumpall as recommended by Immich documentation..."
|
||||
# Use pg_dumpall with recommended flags: --clean and --if-exists
|
||||
if ! docker exec -t immich_postgres pg_dumpall \
|
||||
@@ -358,6 +391,11 @@ fi
|
||||
|
||||
log_message "Database backup completed successfully!"
|
||||
|
||||
# Update metrics for database backup completion
|
||||
if [[ "$METRICS_ENABLED" == "true" ]]; then
|
||||
metrics_file_backup_complete "${DB_BACKUP_PATH}" "database" "success"
|
||||
fi
|
||||
|
||||
# Compress the database backup file
|
||||
log_message "Compressing database backup file..."
|
||||
if ! gzip -f "${DB_BACKUP_PATH}"; then
|
||||
@@ -366,6 +404,12 @@ fi
|
||||
|
||||
echo ""
|
||||
echo "=== PHASE 2: UPLOAD DIRECTORY BACKUP ==="
|
||||
|
||||
# Update metrics for uploads backup phase
|
||||
if [[ "$METRICS_ENABLED" == "true" ]]; then
|
||||
metrics_update_status "running" "Starting upload directory backup"
|
||||
fi
|
||||
|
||||
log_message "Backing up user upload directory: ${UPLOAD_LOCATION}"
|
||||
|
||||
# Verify the upload location exists
|
||||
@@ -377,6 +421,12 @@ fi
|
||||
# Create compressed archive of the upload directory
|
||||
# According to Immich docs, we need to backup the entire UPLOAD_LOCATION
|
||||
# which includes: upload/, profile/, thumbs/, encoded-video/, library/, backups/
|
||||
|
||||
# Update metrics for upload backup phase
|
||||
if [[ "$METRICS_ENABLED" == "true" ]]; then
|
||||
metrics_update_status "running" "Starting upload directory backup"
|
||||
fi
|
||||
|
||||
log_message "Creating compressed archive of upload directory..."
|
||||
log_message "This may take a while depending on the size of your media library..."
|
||||
|
||||
@@ -392,6 +442,11 @@ fi
|
||||
|
||||
log_message "Upload directory backup completed successfully!"
|
||||
|
||||
# Update metrics for uploads backup completion
|
||||
if [[ "$METRICS_ENABLED" == "true" ]]; then
|
||||
metrics_file_backup_complete "${UPLOAD_BACKUP_PATH}" "uploads" "success"
|
||||
fi
|
||||
|
||||
# Resume the Immich server only if it was running and we paused it
|
||||
if [ "${IMMICH_SERVER_RUNNING:-true}" = true ]; then
|
||||
log_status "Resuming immich_server container..."
|
||||
@@ -402,6 +457,12 @@ fi
|
||||
|
||||
echo ""
|
||||
echo "=== COPYING BACKUPS TO SHARED STORAGE ==="
|
||||
|
||||
# Update metrics for shared storage phase
|
||||
if [[ "$METRICS_ENABLED" == "true" ]]; then
|
||||
metrics_update_status "running" "Copying backups to shared storage"
|
||||
fi
|
||||
|
||||
SHARED_BACKUP_DIR="/mnt/share/media/backups/immich"
|
||||
|
||||
# Initialize COPY_SUCCESS before use
|
||||
@@ -472,6 +533,12 @@ if [ "$NO_UPLOAD" = true ]; then
|
||||
B2_UPLOAD_SUCCESS="skipped"
|
||||
else
|
||||
echo "=== UPLOADING TO BACKBLAZE B2 ==="
|
||||
|
||||
# Update metrics for B2 upload phase
|
||||
if [[ "$METRICS_ENABLED" == "true" ]]; then
|
||||
metrics_update_status "running" "Uploading backups to Backblaze B2"
|
||||
fi
|
||||
|
||||
B2_UPLOAD_SUCCESS=true
|
||||
|
||||
# Upload database backup from local location
|
||||
|
||||
Reference in New Issue
Block a user