Software & Applications

Back Up Self-Hosted n8n to S3 Without Losing Your Instance

Learn how to back up self-hosted n8n workflows to S3, protect keys and databases, verify copies, and restore one workflow or the full instance safely.

Self-hosted n8n database and encryption key backup to S3 storage
Self-hosted n8n database and encryption key backup to S3 storage

Yes. A self-hosted n8n workflow can export workflow JSON and upload it to Amazon S3 or compatible object storage. A disaster-recovery backup needs more than workflow JSON. Include the database, N8N_ENCRYPTION_KEY, credentials or a safe recreation plan, needed execution data, and deployment settings. Then prove you can restore the objects in an isolated n8n instance.

The short answer: export workflows, but do not stop there

Workflow JSON can recreate nodes, connections, names, and settings. It cannot recreate the database, encrypted credentials, users, execution history, encryption key, or Docker configuration.

A practical backup set contains:

  • Workflow definitions from the n8n CLI, API, or a controlled filesystem process.
  • The database, usually SQLite or PostgreSQL. Include records for users, credentials, workflow state, and retained execution data.
  • The exact N8N_ENCRYPTION_KEY, stored separately from ordinary application settings and protected by recovery controls.
  • Docker Compose files, image references, reverse-proxy settings, mounted paths, environment-variable names, and deployment scripts.
  • External queue-mode services, such as PostgreSQL and Redis, with their connection settings.
  • Execution data needed for recovery, auditing, or investigation. Large execution histories can use a separate retention policy.

The n8n template research describes exporting workflows and credentials to S3-compatible storage. Credential export needs a self-hosted installation with filesystem access. Confirm its behavior for the n8n release you run. An ordinary workflow export may not contain usable credential secrets. Encrypted credential data also needs the matching encryption key.

Treat workflow export as one layer. Independent backups of the database, configuration, key, and dependencies support full-instance recovery.

A self-hosted n8n server is shown with database backup files for preserving the instance.
A self-hosted n8n server is shown with database backup files for preserving the instance.

Decide what your n8n backup must contain

First, choose the recovery result you need. The source and restore method differ for Docker with SQLite, Docker with PostgreSQL, and queue mode.

Recovery outcomeData to preserveSuitable source
Recover one workflowThat workflow's JSON and referenced credential namesCLI or API export
Rebuild workflows on a clean instanceAll workflow JSON, deployment settings, and safely recreated credentialsCLI or API plus secret management
Recover the n8n applicationDatabase, encryption key, configuration, and application versionDatabase dump plus configuration backup
Recover queue modePostgreSQL, Redis configuration, workers, main process, and deployment filesDatabase and infrastructure backup
Investigate past runsExecution data and files referenced by those runsDatabase and separate file backup

With Docker, copying a volume is not automatically a full backup. It can miss an external PostgreSQL database, Redis, mounted binary-data directories, or the Compose and environment files needed to start the same layout. Queue mode expands the recovery boundary. Back up the database and queue dependency, then record worker and main-process settings.

For workflow exports, follow the current CLI instructions for your n8n version. This commonly used command exports all workflows, but flags and credential-export behavior can change:

n8n CLI
n8n export:workflow --all --output=/backup/workflows.json

Read the official n8n CLI documentation before using this command in production. The API helps when a separate backup host can authenticate to n8n. Filesystem and database backups are the relevant layers for full-instance recovery.

Keep N8N_ENCRYPTION_KEY, database passwords, API tokens, and exported credential material out of ordinary workflow JSON and public repositories. Store them in a restricted secret store or encrypted backup archive. If you use an n8n credential-export procedure, confirm its filesystem requirements and behavior for your installed release before you rely on it.

Build an S3 backup that cannot quietly expose secrets

Use a separate disaster-recovery job, even if an n8n workflow also exports workflow JSON. A workflow inside n8n cannot help if n8n, its database, or its credential encryption key is unavailable. The n8n template approach offers a secondary export. It retrieves workflows through the API, stores them under structured S3 paths, and can export credentials for self-hosted installations with filesystem access.

Create a dedicated S3 bucket or backup prefix. Give each job a separate IAM identity with only the actions it needs. A write job may create objects under a backup prefix. A restore operator needs read access, while retention cleanup needs delete access. Do not give the n8n runtime broad administrator rights. Confirm IAM action names and policy conditions in current AWS documentation, especially with KMS or an S3-compatible provider.

Enable bucket encryption and object versioning where supported. Customer-managed KMS encryption also needs the required key permissions for the backup identity. Add retention through bucket lifecycle controls or the backup system. Confirm that it cannot delete the only known-good restore point. For immutable protection, check whether the provider supports object lock or equivalent retention control, and configure it before use.

Use predictable, non-secret object names. For example:

S3 object names
n8n-backups/instance-a/2026-12-06T020000Z/workflows.json
n8n-backups/instance-a/2026-12-06T020000Z/postgres.sql.gz
n8n-backups/instance-a/2026-12-06T020000Z/manifest.json

The manifest should record the backup timestamp, source instance, n8n version, database type, export counts, archive names, and checksums. It must not contain passwords or encryption keys. Keep key material in a separately protected object or secret store. Give access only to the recovery process.

A separate host, scheduled job, or backup service should collect the database dump and configuration before uploading them. For PostgreSQL, use a version-appropriate pg_dump process and test its output. For SQLite, follow current n8n guidance on stopping or quiescing n8n before copying the database. An online file copy can be inconsistent. Apply the same care to binary data and mounted directories.

An n8n schedule can upload workflow JSON through the API and an S3 node. One published template uses paths such as workflows/{workflowId}/{date}.json and includes retention handling. Keep this as a secondary export, not the only copy. Run the independent job outside n8n. It should not depend on the same server, database, credentials, or network path it protects.

Before automating deletion, upload a new backup and verify it. Confirm that at least one older restore point remains. Use the AWS CLI or an equivalent client only from a protected machine. Supply credentials through its supported mechanism, not shell history or source files.

Verify the object and rehearse a real restore

A successful S3 upload proves only that an object was accepted. It does not prove that the file is complete, readable, decryptable, or usable by n8n. A real restore test must check the files, credentials, workflows, database, and deployment.

  1. Record the expected inventory before export. Count workflows, identify the database dump, and note the n8n version and backup timestamp.
  2. Export the workflows and create database and configuration backups. Stop the job if a required source is missing or a dump command returns an error.
  3. Upload each object to its dated S3 prefix. Write the manifest only after every required upload finishes.
  4. Download the objects into a temporary directory with a separate read-capable identity. Compare downloaded checksums with the manifest. Confirm that archive sizes are plausible for this instance.
  5. Parse the workflow export as JSON. Compare its workflow count with the source count. Check expected workflow IDs and names without printing credential values.
  6. Inspect S3 metadata, version IDs where enabled, timestamps, and encryption status. Confirm that the object remains readable after the upload process ends.
  7. Restore one workflow into a disposable n8n instance. Use the matching encryption key when encrypted credentials are part of the test. Otherwise, deliberately recreate credentials if the export excludes their secret values.
  8. Run a safe test execution with external side effects disabled or replaced. Confirm that nodes load, credentials resolve as intended, expressions work, and the workflow can be activated without contacting production systems.
  9. Restore the full instance into an isolated environment. Recreate Docker or Compose settings, restore the database, place the encryption key in the expected environment setting, restore required mounted files, and start the main process before workers.
  10. If you use queue mode, restore PostgreSQL and the queue dependency. Start the matching worker configuration. Check that jobs are claimed, executions are recorded, and no test event can reach production.

The restore is complete when the disposable instance starts, expected workflows and credentials work, a controlled execution completes, and restored data matches the manifest. If any condition fails, mark the backup untrusted and stop the drill. Do not change production.

Use this failure checklist before you trust the backup

Run these checks after every backup change and on a schedule that fits your recovery needs. Confirm current n8n export behavior, CLI flags, credential handling, and AWS or S3-compatible storage policies in the official documentation for your versions and provider.

  • Credential leakage: Search manifests, logs, temporary files, and workflow exports for tokens, passwords, private keys, and credential values. Remove temporary files according to your operating system and secret-management policy.
  • Missing encryption key: Confirm that the key uses a separately protected backup path. Test that a disposable restore can decrypt the restored credential records.
  • Database omission: Confirm that the backup includes n8n's real database. A Docker volume copy is misleading if production uses external PostgreSQL.
  • Expired S3 credentials: Alert on authentication failures. Test the backup identity before its key-rotation deadline. Prefer short-lived or role-based access where supported.
  • Partial uploads: Require every expected object and a completed manifest. A zero-length or truncated workflow file must fail the job.
  • Wrong permissions: Test write, read, version-listing, and retention operations with separate identities. Least privilege means deciding these permissions separately, not granting one identity full bucket control.
  • Circular scheduling: Keep the disaster-recovery copy outside n8n. An internal schedule is a convenience export, not an independent backup.
  • Silent workflow changes: Compare export counts and IDs with the previous manifest. A sudden empty export should alert instead of replacing the last known-good copy.
  • Retention mistakes: Check lifecycle and versioning behavior in the provider console or API. Confirm that cleanup cannot remove every restorable version.
  • Untested restore: Record the date and result of the last disposable restore. An upload is not a recovery test until n8n can read the data and perform a controlled execution.

Configure alerts for failed jobs, missing manifests, unexpected count changes, checksum mismatches, permission errors, and restore-test failures. Keep the runbook with the backup location, but not with unprotected secrets.

Conclusion

A sound self-hosted n8n backup has two layers. The first is a portable workflow export for quick recovery. The second is an independent disaster-recovery set with the database, encryption key, credential strategy, deployment configuration, and queue or file dependencies. Store both in protected, versioned S3 storage. Verify downloads and checksums, then rehearse a disposable restore. That turns an S3 object into a recovery plan.

Frequently Asked Questions

Can an n8n workflow back itself up to S3?

Yes. An n8n workflow can use the API or export steps with an S3 node to save workflow JSON. Published templates also describe workflow and credential backups for self-hosted installations. It cannot be the only backup. The workflow stops being available if n8n, its database, credentials, or encryption key is unavailable. Use an external scheduled job for the database and full-instance backup.

Are credentials included in an n8n workflow export?

Not necessarily, and you should not treat them as safely included. Workflow JSON may reference credentials without containing usable secret values. Encrypted credential data needs the matching N8N_ENCRYPTION_KEY. Check your n8n version's export behavior, protect any credential export, and test a disposable restore before calling the backup complete.

Should I use the n8n CLI, API, or a database dump?

Use the CLI or API for portable workflow definitions. Use a database dump for full-instance recovery. The CLI supports scheduled exports, the API works from a separate backup service, and the database preserves application state that workflow JSON cannot. Docker volume copies alone are insufficient when PostgreSQL, Redis, or mounted data lives elsewhere.

Sources

Automation & Infrastructure Desk

Think Tech Editorial

Engineering guides focused on reliable self-hosted workflows, reverse proxies, and production diagnostics.