#!/bin/bash

# === CONFIGURATION ===
BACKUP_NAME="kot"                     # Name of the backup
SNAPSHOT_NAME="$(date +%Y-%m-%d-%H%M)"         # Unique snapshot name
DRY_RUN="--dry-run=true"
export PBS_FINGERPRINT="be:e1:16:01:34:26:e7:27:a5:c0:ef:d5:54:27:02:38:ea:94:6d:fc:d1:6e:c5:b2:ec:7d:c3:d9:d5:32:9e:c0"
export PBS_REPOSITORY=bck_ops@pbs@vmx-pbs.swallow-grue.ts.net:vmx-pbs_data1
# export PBS_REPOSITORY=bck_ops@pbs!bck_ops_key@vmx-pbs.swallow-grue.ts.net:vmx-pbs_data1
export PBS_PASSWORD_FILE=/root/.pbs_password
BCK_SRC=$1
BCK_DST=$2
HC_ID=$3
MY_HOSTNAME=$(hostname)

apt clean cache
mkdir -p /root/backup
sudo -u postgres pg_dump authelia_db | gzip > /root/backup/authelia_$(date +%F).sql.gz
dpkg --get-selections > /root/backup/packages-list.txt


# SPECS=""
# while IFS= read -r line; do
#     NAME=$(basename "$line")
#     [ -d "$line" ] && SPECS+="$NAME.pxar:$line "
# done < /root/backup_src.txt

BCK_SRC="etc.pxar:/etc \
home.pxar:/home \
root.pxar:/root \
srv.pxar:/srv \
usr-local.pxar:/usr/local \
boot.pxar:/boot opt.pxar:/opt \
log.pxar:/var/log \
var-lib.pxar:/var/lib"


# === BACKUP COMMAND ===
proxmox-backup-client backup $BCK_SRC --backup-id "$BACKUP_NAME" 

# === END ===