#!/bin/bash stop_container() { local c="$1" log "Stopping $c..." docker stop "$c" || { log "Error stopping $c"; exit 1; } } start_container() { local c="$1" log "Starting $c..." docker start "$c" || { log "Error starting $c"; exit 1; } } enable_maintenance_mode() { local c="$1" local cmd="$2" log "Enabling maintenance mode for $c..." docker exec -u www-data "$c" "$cmd" || { log "Error enabling maintenance mode"; exit 1; } } disable_maintenance_mode() { local c="$1" local cmd="$2" log "Disabling maintenance mode for $c..." docker exec -u www-data "$c" "$cmd" || { log "Error disabling maintenance mode"; exit 1; } } dump_postgres_db() { local c="$1" local user="$2" local path="$3" log "Dumping PostgreSQL db..." docker exec -t "$c" pg_dumpall --clean --if-exists --username="$user" --file="$path" || { log "Error dumping PostgreSQL"; exit 1; } } dump_mariadb_db() { local c="$1" local user="$2" local pass="$3" local db="$4" local path="$5" log "Dumping MariaDB/MySQL db..." docker exec "$c" mariadb-dump --single-transaction -h localhost -u "$user" -p"$pass" "$db" > "$path" || { log "Error dumping MariaDB/MySQL"; exit 1; } } dump_sqlite_db() { local src="$1" local dst="$2" log "Dumping SQLite db..." sqlite3 "$src" ".backup $dst" || { log "Error dumping SQLite"; exit 1; } } run_duplicati_backup() { local c="$1" local dest="$2" local name="$3" local versions="$4" local sftp_user="$5" local sftp_pass="$6" local passphrase="$7" local fingerprint="$8" shift 8 local sources=("$@") log "Running duplicati backup for $name..." docker exec "$c" duplicati-cli backup "$dest" "${sources[@]}" \ --backup-name="$name" \ --keep-versions="$versions" \ --auth-username="$sftp_user" \ --auth-password="$sftp_pass" \ --passphrase="$passphrase" \ --ssh-fingerprint="$fingerprint" \ --prefix="$name" || { log "Error in duplicati backup for $name"; exit 1; } log "$name backup complete." }