← Recipes
Backup & recovery
Back up PostgreSQL to S3
Create a timestamped PostgreSQL dump and upload it to an S3-compatible bucket every night.
Supported platforms
LinuxmacOS
Prerequisites
- pg_dump
- An S3-compatible bucket
- Database and S3 credentials exposed through environment-backed Dagu secrets
Workflow YAML
description: Create a PostgreSQL custom-format dump and upload it to S3.
schedule: "0 2 * * *"
params:
- name: database_name
default: app
description: Safe name used in the backup filename
- name: bucket
required: true
description: Destination S3 bucket
- name: prefix
default: postgres
description: Object key prefix
secrets:
- name: DATABASE_URL
provider: env
key: DATABASE_URL
- name: AWS_ACCESS_KEY_ID
provider: env
key: AWS_ACCESS_KEY_ID
- name: AWS_SECRET_ACCESS_KEY
provider: env
key: AWS_SECRET_ACCESS_KEY
defaults:
retry_policy:
limit: 2
interval_sec: 30
steps:
- id: create_dump
run: |
#!/bin/sh
set -eu
timestamp="$(date -u +%Y%m%dT%H%M%SZ)"
file="$DAG_RUN_WORK_DIR/${params.database_name}-${timestamp}.dump"
key="${params.prefix}/${params.database_name}-${timestamp}.dump"
pg_dump --format=custom --file="$file" "$DATABASE_URL"
printf 'file=%s\nkey=%s\n' "$file" "$key" >> "$DAGU_OUTPUT_FILE"
outputs:
- name: file
- name: key
- id: upload
depends: [create_dump]
action: s3.upload
with:
bucket: ${params.bucket}
key: ${steps.create_dump.outputs.key}
source: ${steps.create_dump.outputs.file}
content_type: application/octet-stream
Review before running
Replace example values, configure the listed secrets, and review every command for your environment. Syntax validation does not make a community workflow trusted.
Running this workflow with a team?
The Team plan adds SSO, role-based access, audit logs, incident routing, and priority support for three self-hosted Dagu servers. Start a 14-day trial without a credit card.
Start Team trial