feat(id.tjo.space): simplify backup

This commit is contained in:
Tine 2025-03-09 16:51:02 +01:00
parent 878b595bab
commit d24cd9489d
Signed by: mentos1386
SSH key fingerprint: SHA256:MNtTsLbihYaWF8j1fkOHfkKNlnN1JQfxEU/rBU8nCGw
2 changed files with 5 additions and 11 deletions
id.tjo.space/root/etc/systemd
system-environment-generators
system

View file

@ -0,0 +1,3 @@
#!/bin/bash
echo "CURRENT_DATE=$(date +%Y_%m_%d)"
echo "CURRENT_DATETIME=$(date +%Y-%m-%d_%H-%M-%S)"

View file

@ -2,20 +2,11 @@
Description=Backup PostgreSQL databases
[Service]
Restart=always
Environment=PODMAN_SYSTEMD_UNIT=%n
KillMode=mixed
ExecStop=/usr/bin/podman rm -v -f -i --cidfile=%t/%N.cid
ExecStopPost=-/usr/bin/podman rm -v -f -i --cidfile=%t/%N.cid
Delegate=yes
Type=notify
NotifyAccess=all
SyslogIdentifier=%N
Type=oneshot
EnvironmentFile=/etc/postgresql/secrets.env
EnvironmentFile=/etc/postgresql/postgresql.env
Environment=BACKUP_DIR=/srv/postgresql/backups
Environment=POSTGRES_HOST=systemd-postgresql
ExecStartPre=/usr/bin/mkdir -p $BACKUP_DIR
ExecStart=/usr/bin/podman run --name=systemd-%N --cidfile=%t/%N.cid --replace --rm --cgroups=split --network systemd-main --sdnotify=conmon -d -v $BACKUP_DIR:/backups docker.io/library/postgres:17.4 -- pg_dumpall -U $POSTGRES_USER -h $POSTGRES_HOST -p $POSTGRES_PORT -f /backups/$(date +'%Y-%m-%d_%H-%M-%S').sql
ExecStart=podman run --name=systemd-%N --replace --rm --network systemd-main -v ${BACKUP_DIR}:/backups -e PGPASSWORD=$POSTGRES_PASSWORD docker.io/library/postgres:17.4 pg_dumpall -U $POSTGRES_USER -h $POSTGRES_HOST -f /backups/$CURRENT_DATETIME.sql