#!/bin/bash log() { local message="$1" echo "$(date '+%Y-%m-%d %H:%M:%S') - $message" | tee -a "$LOG_FILE" } 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..." # we explcitly do not want to stringify here # shellcheck disable=SC2086 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..." # we explcitly do not want to stringify here # shellcheck disable=SC2086 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 for $c..." 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 for $c..." 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 for $c..." sqlite3 "$src" ".backup $dst" || { log "Error dumping SQLite"; exit 1; } } run_duplicati_backup() { local dest="$1" local name="$2" local versions="$3" local sftp_user="$4" local sftp_pass="$5" local fingerprint="$6" local passphrase="$7" shift 7 local sources=("$@") log "Running duplicati backup for $name..." docker exec duplicati duplicati-cli backup "ssh://$dest" "${sources[@]}" \ --backup-name="$name backup" \ --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." }