infrastructure-ng/id.tjo.space/root/etc/systemd/system/postgresql-backup.service

25 lines
1 KiB
SYSTEMD
Raw Normal View History

[Unit]
Description=Backup PostgreSQL databases
[Service]
Delegate=yes
Type=notify
NotifyAccess=all
SyslogIdentifier=%N
Environment=PODMAN_SYSTEMD_UNIT=%n
KillMode=mixed
EnvironmentFile=/etc/postgresql/secrets.env
EnvironmentFile=/etc/postgresql/postgresql.env
Environment=BACKUP_DIR=/srv/postgresql/backups
2025-03-09 14:57:59 +00:00
Environment=POSTGRES_HOST=systemd-postgresql
2025-03-09 15:10:29 +00:00
ExecStartPre=/usr/bin/systemd stop authentik-server authentik-worker
2025-03-09 14:57:59 +00:00
ExecStartPre=/usr/bin/mkdir -p $BACKUP_DIR
ExecStart=/usr/bin/podman run --name=systemd-%N --cidfile=%t/%N.cid --cgroups=split --sdnotify=conmon --detach --replace --rm --network systemd-main -v ${BACKUP_DIR}:/backups -e PGPASSWORD=${POSTGRES_PASSWORD} docker.io/library/postgres:17.4 pg_dump --username=${POSTGRES_USER} --host=${POSTGRES_HOST} --format=custom --file=/backups/${CURRENT_DATETIME}.sql ${POSTGRES_DB}
ExecStop=/usr/bin/podman rm -v -f -i --cidfile=%t/%N.cid
ExecStopPost=-/usr/bin/podman rm -v -f -i --cidfile=%t/%N.cid
ExecStopPost=/usr/bin/systemd start authentik-server authentik-worker