Self-hosting n8n on AWS: backups, a tested restore and alerts
How to back up n8n on AWS so you can get it back: what to save, why the encryption key lives apart from the database, a practice restore, and alerts.

Maulik Joshi
Full-Stack Developer
Developers who host n8n on AWS without an operations team will find the whole setup here, from backups to alerts. It exists because a backup nobody has restored is only an assumption, and a missing secret key can leave every saved login in a restored copy unreadable. After following it, you will be able to run a practice restore and check that your workflows and saved logins come back working.
A self-hosted n8n (n8n running on a server you manage) can be recovered only if you keep two things together: a database backup, and the N8N_ENCRYPTION_KEY, the secret key n8n uses to lock the saved logins (credentials) stored in that database. If you restore the database without the key, n8n starts and shows your workflows, but every saved credential fails to decrypt, which means n8n cannot unlock it. A backup that has never been restored into a clean environment is only an assumption. This runbook, a step-by-step operating guide, sets up the layout, the backups and the alerts, then walks through a restore drill (a practice restore into a fresh copy) and the checks that tell you it worked.
The reader is a developer who runs n8n on AWS without a platform team. The layout is one EC2 instance (a single virtual server) running n8n and Traefik (the web proxy that serves n8n over HTTPS) with Docker Compose, and the database on RDS for PostgreSQL (AWS's managed database service). I checked every command, variable and behavior below against n8n's documentation and AWS's documentation on November 22, 2026. n8n's docs listed 2.48.7 as the stable version that day, and n8n 3.0 was an early-access release. I could not run AWS commands while writing this, and I parsed the compose files as YAML without starting them, so treat the steps as documented, not field-tested. The drill is yours to run and time, which is why this post contains no restore time, cost or uptime figure.
#What you need before you start
- An AWS account where you can create EC2, RDS, CloudWatch, SNS and Route 53 resources, and the AWS CLI v2 configured for it.
- A Linux EC2 instance with Docker Engine and Docker Compose v2 installed, an Elastic IP address (AWS recommends one for a health-checked EC2 endpoint, and it keeps your DNS record valid), and a DNS A record for the subdomain n8n will use.
- A password manager entry, or an AWS Secrets Manager secret, that you can reach without the n8n server. It will hold the encryption key.
- A second, short-lived machine in the same VPC for the restore drill. The database will not be publicly reachable, so a laptop cannot connect to it.
#What n8n keeps, and where it lives
n8n's backup page lists what needs protecting. In this layout it sits in five places, and they fail independently.
| State | Where it lives here | What backs it up | If you lose it |
|---|---|---|---|
| Workflows, users, variables, execution history | The RDS PostgreSQL database | RDS automated backups and manual snapshots | Everything you built. Point-in-time restore returns the database to a chosen moment inside the retention period. |
| Credentials, stored encrypted | The same database | The same backups, readable only with the key below | n8n cannot decrypt them, and each credential has to be created again. |
| The encryption key | N8N_ENCRYPTION_KEY in .env, and the config file inside the n8n_data volume once n8n has started | Your password manager or Secrets Manager, with an EBS snapshot of the host as a second copy | The database restores but its credentials do not decrypt. |
| Binary data (files passing through workflows) | Memory by default. With N8N_DEFAULT_BINARY_DATA_MODE=filesystem, the n8n_data volume | EBS snapshots of the host volume | Files from past executions. n8n prunes them along with the executions anyway. |
| Deployment config | compose.yaml and .env on the host | A private Git repository for compose.yaml, with the secrets kept in the password manager | Time. You can rebuild it from this post, but you cannot rebuild the key. |
The key decides whether a restore is usable. n8n's backup page says that without it, "a restored database or encrypted credential export can't be decrypted." When the key is wrong, n8n shows this error as soon as you open or run a credential: Credentials could not be decrypted. The likely reason is that a different "encryptionKey" was used to encrypt the data. I took that message from n8n's source code for the 2.48.7 release. A database snapshot holds the database. It does not hold a line in a .env file or a file in a Docker volume, so the key needs its own copy somewhere that survives the loss of the server.
If you load custom nodes through N8N_CUSTOM_EXTENSIONS, back up that directory too, because workflows that use those nodes will not run without it.
#Where should the database live: RDS or the same server?
n8n uses SQLite unless you set DB_TYPE=postgresdb, and PostgreSQL is the only other database it supports, since MySQL and MariaDB were deprecated in version 1.0. Its Docker Compose guide says SQLite is fine for trying things out and recommends Postgres for a production instance that has to handle more than a handful of users or workflows running around the clock. Queue mode, n8n's way of scaling out with workers, does not support SQLite, so starting on Postgres keeps that option open.
| Postgres container on the same EC2 instance | EC2 for n8n, database on RDS | |
|---|---|---|
| Database backup | Yours to build: a scheduled dump, plus EBS snapshots of the instance volume | RDS automated backups with point-in-time restore, plus manual snapshots |
| Restore | Load a dump or restore a volume snapshot | RDS creates a new DB instance with a new endpoint, and you point n8n at it |
| How far back you can go | As far back as the last dump or snapshot that actually ran | Any moment inside the retention period, which RDS allows from 0 to 35 days. RDS uploads transaction logs to S3 every five minutes |
| What fails quietly | The dump job stops, or the instance disk fills | Automated backups do not run while the instance is in a state other than available, such as storage_full |
| What it adds | Fewer parts | A second AWS service to configure and secure |
I would put the database on RDS for anything a clinic or a client depends on, because point-in-time restore becomes a setting you turn on instead of a script you maintain. The one-instance layout is reasonable when you could rebuild everything without losing anything you care about, provided you accept that your recovery point is the last dump and you check that the dump ran. n8n's own AWS guides cover Kubernetes on EKS and a pre-release Terraform module that needs a license, so this runbook covers the smaller layout.
If you take the one-instance route, n8n's hosting repository documents a dump you can adapt, along with a check that the file is complete:
The rest of the steps assume RDS.
#Step 1: create the database on RDS
Create an RDS for PostgreSQL instance on a major version that n8n's documentation lists as supported (its Compose examples run PostgreSQL 18), with an initial database named n8n. The settings I would set on purpose are a private instance with no public access, a security group that allows port 5432 only from the n8n host's security group, storage encryption, deletion protection, and a backup retention period you chose. RDS defaults to 7 days when you create an instance in the console and 1 day when you use the CLI or API, and changing the period from 0 to a nonzero value or back causes an outage, so settle it at creation.
To set it on an existing instance, use the command below. Fourteen days is my example. Pick the window you would need if you noticed a bad change late.
Then connect as the RDS master user, to the n8n database, and create a user for n8n so the application never runs as the master. This mirrors the init script in n8n's hosting repository.
What you should see. This query returns the status available, your retention period, true for deletion protection, and a timestamp for the latest restorable time. On a brand-new instance, check again after the first automated backup finishes, which RDS reports as event RDS-EVENT-0002.
#Step 2: create the encryption key before n8n starts
n8n generates a random key on first launch and saves it in the config file under .n8n unless you provide one. Provide your own first, and store it before anything depends on it. Any long random string works. This one produces 64 hex characters:
Paste the output into your password manager or Secrets Manager now, then into .env in the next step. The order matters because of a rule in n8n's source (packages/core/src/instance-settings/instance-settings.ts, tag n8n@2.48.7, which I read rather than found in the docs). If a config file already exists and N8N_ENCRYPTION_KEY holds a different value, n8n refuses to start and prints: Mismatching encryption keys. The encryption key in the settings file does not match the N8N_ENCRYPTION_KEY env var. Please make sure both keys match.
If you already started n8n once without setting the variable, nothing is lost. Read the key it generated, store it, and put the same value in .env:
#Step 3: start n8n against RDS
The compose file below is n8n's Docker Compose guide with five changes. It pins the image version, because n8n releases most weeks and its update guide tells queue-mode users to pin a tag instead of latest. It points n8n at RDS and drops the Postgres container. It sets the encryption key from .env. It turns on filesystem binary data so large files do not sit in memory. And it removes the --api.insecure=true line, since the Traefik dashboard is not needed and was not published in that file anyway.
n8n's Terraform maintenance page notes that the RDS server certificate chains to Amazon's certificate authority, which Node.js does not trust by default. Its module therefore encrypts the database connection without verifying it, unless you supply the CA bundle. The file below supplies it, so the connection is encrypted and verified. First create the folders and download the bundle that AWS publishes for all commercial regions:
Set DB_HOST to your RDS endpoint, paste the key from step 2, then lock the file down and start the stack:
What you should see. Both containers are running, and the readiness endpoint answers with status 200. n8n documents that endpoint as returning 200 only when the database is connected and migrated, so it covers the RDS connection as well as the web server. The first visit to the URL shows owner account setup.
Where it fails. If n8n exits right after starting, read docker compose logs n8n. A mismatching-keys line means step 2 went out of order. A database connection error usually means the security group on RDS does not allow the host, or DB_HOST is wrong. A certificate verification error means the bundle is missing or the mount path does not match DB_POSTGRESDB_SSL_CA_FILE.
Last, confirm the running key is the one you stored. Because the variable was set before the first start, the config file should contain the same value. Compare it with your password manager entry using the command from step 2. Then create the owner account, one workflow, and one credential that has a Test button. The drill needs something to prove.
#Step 4: back up the database
Automated backups run in the backup window you configured, and RDS saves them for the retention period. A manual snapshot adds a restore point you choose, and it does not expire. AWS says manual snapshots are not subject to the retention period, you can keep up to 100 per Region, and they survive deleting the instance, while automated backups are deleted with the instance unless you choose to retain them. Take a manual snapshot before every change to n8n or to the database, starting with the first update.
What you should see. The status moves from creating to available. On a single-AZ instance, AWS warns that taking a snapshot causes a brief I/O suspension that can last from a few seconds to a few minutes, so avoid your busiest hour. The instance must be in the available state to be snapshotted, and automated backups also pause while it is in any other state. That includes storage_full, which is why the storage alert in the alerts section protects your backups as well as your uptime.
One caution from n8n's Terraform maintenance page. If you encrypt the database with a KMS key and that key is scheduled for deletion, snapshots encrypted with it can no longer be decrypted. Keep the key outside anything you might tear down.
#Step 5: snapshot the host volume
AWS does not back up EBS volumes for you. Its documentation says creating snapshots regularly, or automating them with Amazon Data Lifecycle Manager or AWS Backup, is your responsibility. Snapshots are incremental and are stored in S3 buckets you cannot access directly. The host volume holds compose.yaml, .env, the n8n_data volume (the config file, plus binary data in filesystem mode) and Traefik's certificate data. Create a Data Lifecycle Manager policy or an AWS Backup plan that snapshots it on a schedule. I would use daily, but the right interval depends on how much binary data you can afford to lose. This snapshot is the second copy of your key, not the first. The database is on RDS, so there is no database file on this volume to copy in an inconsistent state.
#Step 6: export workflows and credentials as a third layer
The n8n CLI can write every workflow and credential to JSON. The --backup flag is shorthand for --all --pretty --separate, which gives one file per item. n8n says to use a separate output directory for each command, and to bind-mount a host directory in Docker because a backups folder inside the container is not persisted. The compose file already mounts ./local-files at /files.
To run these from a scheduler, drop the -it flags. Then copy local-files/backups off the host, for example to an S3 bucket, so the export does not live only on the machine it protects. What you should see is one JSON file per workflow, so the file count in the workflows folder matches the number of workflows in the editor.
This layer has limits. The credentials export stays encrypted with your key by default. The --decrypted flag writes plain text, and n8n says to store such a file with the same care as the credentials themselves and delete it after the restore, so I would never make it your routine backup. The export also omits users and roles, execution history, variables and instance settings, including the key, which is why n8n says it can move workflows between instances but cannot recover a full instance on its own.
#Step 7: run the restore drill
The drill proves four things: the database restores, the key opens the credentials, n8n boots on the restored copy at the same version, and you know the sequence before an incident. Run it once after the first setup, after any change to the layout, and on a schedule you will keep. The restored copy contains the same data as production, so give it the same protection and delete it at the end.
#7.1 Restore the database to a new instance
A restore never writes over the source. For a point-in-time restore, AWS creates a new DB instance without modifying the source. A snapshot restore also creates a new instance, and AWS states you cannot restore a snapshot onto an existing one. Start a stopwatch, then run one of these. The first restores to the latest restorable time and the second to a snapshot from step 4.
Check three settings before you trust the result. The restored instance gets the default parameter and option groups unless you name others at restore time with the CLI or API. It gets the default VPC security group unless you choose one, so attach a group that lets the drill machine reach port 5432. AWS recommends restoring to the same or a similar instance size, since an incompatible size and IOPS combination can cause an error, and storage cannot be reduced at restore time.
Poll the status until it reads available, and record the time. Then note that the restore is not finished for performance purposes. AWS says that after the instance becomes available its volumes continue loading data from S3 in the background, and the instance is fully operational but may not perform at its best until that completes. For a snapshot restore, data not yet loaded is fetched on first access. Record the available time and the time n8n answered normally as separate numbers.
The new instance has a new endpoint. In a real recovery you would change DB_HOST in .env and restart n8n, which is one reason the database host lives in one variable in this layout.
#7.2 Start n8n on the copy without letting it run workflows
On the drill machine, create a folder with the compose.drill.yaml below, the same certs/global-bundle.pem, and a .env that holds N8N_VERSION, DB_HOST (the drill endpoint), DB_NAME, DB_USER, DB_PASSWORD, and N8N_ENCRYPTION_KEY copied from your password manager. Do not copy the key from the production host. The point of the drill is to prove the stored copy works. Use the same N8N_VERSION as production, because n8n only migrates a database forward and n8n's update guide says changing the image tag back does not reverse migrations.
Unpublish everything before the first start. The restored database contains your published workflows and your real credentials. Started normally, the copy would fire its schedule triggers and could message real people or write to real systems. n8n's CLI can unpublish every workflow in the database before the first start, and its docs say the Server CLI can run most commands while n8n is not running, and that a publish or unpublish change is applied when n8n next starts. The n8n image's entrypoint passes its arguments to the n8n binary, so a one-off container does the job.
I have not run these commands. The drill file sets N8N_SECURE_COOKIE=false because n8n defaults it to true, which sends cookies only over HTTPS, and you are reaching the copy over a plain-HTTP tunnel at http://localhost:5678. Never set it on the production file.
#7.3 Check the result
- Readiness. Run curl -i http://localhost:5678/healthz/readiness and expect 200. A failure here means n8n cannot reach the restored database. Check the security group and the endpoint in .env.
- Users. Sign in with the production owner email and password. If n8n shows the first-run owner setup instead, it connected to an empty database, so check DB_NAME.
- Workflows. The count should match the production editor at the restore time, or the number of files in your latest export. Every workflow should show as unpublished.
- Credentials. Open the credential you created in step 3 and use its Test button, or run a workflow that uses it and is safe to run. If you see Credentials could not be decrypted, the key in the drill .env is not the key that encrypted the data.
- Executions. The newest execution should be from just before the restore time. Anything after it is gone. Anything older than your pruning window is gone too, because n8n prunes executions by default after 336 hours (14 days) or when more than 10,000 are stored, whichever comes first.
- Binary data. In filesystem mode, files live in the n8n_data volume and not in the database. Open an old execution that handled a file. If you need those files, you must also restore the EBS snapshot, so test that once too.
Optionally, test the export layer too. On a clean instance, complete owner setup first, because imports need an existing user, then run n8n import:workflow --separate --input=/files/backups/workflows/ and the matching credentials command from its own folder. n8n warns that items with matching IDs are overwritten, that imported workflows are deactivated by default, and that import:credentials --separate fails if the input folder also holds workflow files. Imported credentials are readable only if the new instance uses the same key, or you exported with --decrypted.
#7.4 Record it and tear it down
Write down the date, the restore point (a time or a snapshot name), when you started, when RDS said available, when n8n answered normally, the result of each check, and everything that went wrong. Those numbers are the only recovery-time figures that mean anything for your instance. Then delete the copy and anything the drill created:
The down -v flag deletes the drill's own volume, which is what you want here. Never run it against the production compose file, because it would delete n8n_data, which holds the config file and the key. n8n's hosting repository warns about the same thing for its Postgres example.
Once the manual drill works, AWS Backup can repeat part of it. Its restore testing feature runs scheduled restore jobs from your recovery points for resource types that include RDS, EBS and EC2, can run validation, deletes the restored resource afterward and records how long each restore job took. Each test has a cost, so read the AWS Backup pricing page first. It proves the infrastructure restores. It cannot prove that n8n can decrypt a credential with your key, so the checks above stay yours.
#Alerts that reach you before a user does
Every alarm below needs an SNS topic with a confirmed subscription. AWS sends a confirmation email, and only confirmed addresses receive alerts. Make the first alarm fire on purpose once, so you know the path works.
| What you want to know | Signal | Notes |
|---|---|---|
| n8n is down, or cannot reach its database | A Route 53 health check on the public HTTPS URL, path /healthz/readiness, with an alarm on its status | Turn on SNI for the HTTPS check, because Traefik routes by hostname. Route 53 metrics and the alarm's SNS topic live in US East (N. Virginia). HTTPS, string matching and the 10-second interval carry extra charges, so check Route 53 pricing. |
| The host is impaired | The EC2 StatusCheckFailed metric | AWS says to treat an insufficient-data state as missing data, not as a failed check. Simplified automatic recovery is on by default for supported instances and handles system status failures. |
| The host disk is filling | disk_used_percent from the CloudWatch agent | The agent publishes to the CWAgent namespace by default. Docker images, logs and binary data all land on this disk. |
| The database is running out of storage | RDS events RDS-EVENT-0089 (more than 90 percent of allocated storage used) and RDS-EVENT-0007 (storage exhausted) | The FreeStorageSpace metric reports bytes, so a 10 GiB threshold is 10737418240. |
| Backups stopped | LatestRestorableTime, checked from outside n8n | On the RDS events page I read, the backup category lists start (RDS-EVENT-0001) and finish (RDS-EVENT-0002) events and no failure event for an ordinary backup. |
| A workflow failed | An n8n error workflow | Covered below. It cannot report that n8n itself is down. |
The EC2 alarm, using AWS's own example with your values in place of the placeholders:
The RDS low-storage alert is an event subscription, using category names as RDS's event page lists them:
For backup freshness, use the field AWS documents for point-in-time restore. RDS uploads transaction logs every five minutes, so on a healthy instance this value should trail the clock by minutes, which is my inference from that interval. Run the query from a scheduler that is not n8n, such as a cron job on another machine, because a watchdog that lives inside the thing it watches stops when that thing stops. Alert if the timestamp is older than you can accept.
For failed executions, build an error workflow with an Error Trigger node as its first node. In every workflow you want covered, open Options, then Settings, and pick it under Error workflow. The trigger passes the workflow name, the execution URL and the error message, and a Slack or email node can forward them. n8n's page lists four rules that catch people. You have to publish the workflow that contains the Error Trigger. It runs only when an automatic execution fails, so a manual run does not test it. A workflow that contains an Error Trigger uses itself as its error workflow by default. And when a workflow's own trigger node fails, the payload carries a trigger object with less execution detail, and the execution URL is missing if the execution was not saved.
To test the path, build a scheduled workflow whose only job is to fail, for example with a Stop and Error node, publish it, set its error workflow, and wait for the next run. If workflows handle patient data, I would send only the workflow name and the execution URL, and leave the error message out, because I cannot promise what an error message quotes.
#Security and updates, briefly
- TLS at the edge. n8n's compose guide serves n8n over HTTPS only, through Traefik and Let's Encrypt, and the n8n container publishes 5678 on 127.0.0.1 only, so ports 80 and 443 are the only public ones you need.
- No public database. RDS stays private, reachable from the n8n host's security group alone, with its certificate verified through the AWS bundle, and n8n connects as n8n_app, not the master user.
- Secrets. Keep .env at mode 600 and out of Git. n8n says you can add _FILE to individual variables to read a value from a file, which suits Docker secrets if you outgrow .env.
- Updates. n8n recommends updating at least monthly, reading the release notes and testing on a separate instance first. Take a manual snapshot, change N8N_VERSION, then run docker compose pull and docker compose up -d. n8n runs pending migrations at startup and changing the tag back does not reverse them, so the way back is the restore from step 7.
- Before 3.0. n8n's 3.0 notes list breaking changes, and Settings, Migration Report shows what on your instance needs attention. 3.0 turns on encryption key rotation by default, and n8n warns that older versions cannot read data written with the new data key, so take a full database backup first.
If protected health information could pass through n8n, hosting it yourself changes who controls the data. It does not make a workflow compliant. What AWS, n8n and your logs may hold is a decision for the clinic's compliance adviser, and the restore drill copy holds the same data as production, so it needs the same controls and must be deleted afterward. This post is not legal advice. My page on HIPAA-aware software development explains how I approach that work.
#What I would not do
- Keep the only copy of the encryption key on the server it protects.
- Run docker compose down -v on the production stack. It removes the n8n_data volume and the config file with the key.
- Copy the SQLite file while n8n is running and call it a backup.
- Use export:credentials --decrypted as a routine backup, or leave a decrypted file lying around after a restore.
- Treat the CLI export as a full backup. It leaves out users, variables, execution history, instance settings and the key.
- Run the drill on the production instance, or start the restored copy with its workflows still published.
- Use latest as the image tag, or update without a fresh manual snapshot.
- Open port 5432 to the internet, or let n8n connect as the master user.
- Count backups as done because the setting is on. The drill is the proof.
#Questions about backing up self-hosted n8n
#Next step
If you would rather have this designed and tested for your own setup, send me your workflows, what data passes through them and where n8n runs today through an estimate request or the contact page, and I will tell you what is feasible. My healthcare workflow automation page describes how I connect clinic systems with tools like n8n, and my guide to WhatsApp for clinics shows one clinic workflow in detail. The AI Lab lists this guide next to related guides and runnable demos.
Last checked against n8n's and AWS's documentation on November 22, 2026, with n8n stable 2.48.7 and the AWS CLI v2 reference. Both vendors change their docs often, and n8n has moved its documentation to new addresses, so verify against the sources before you build. This is not legal advice.
#Sources
- n8n docs (docs.n8n.io/deploy/host-n8n/): Use Docker Compose, Back up and restore, Use the command line, Update n8n, Monitor n8n, Manage execution data, Handle binary data, and the Database, Deployment, Executions and Security environment variable pages
- n8n docs: Error Trigger node (docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.errortrigger), Deploy to AWS with Terraform and Maintain and tear down the AWS deployment, Rotate encryption keys, v3.0 breaking changes
- n8n source, tag n8n@2.48.7 (github.com/n8n-io/n8n): packages/core/src/instance-settings/instance-settings.ts, packages/core/src/constants.ts, docker/images/n8n/docker-entrypoint.sh
- n8n hosting repository, docker-compose/withPostgres (github.com/n8n-io/n8n-hosting)
- AWS RDS User Guide (docs.aws.amazon.com/AmazonRDS/latest/UserGuide/): automated backups, backup retention period, point-in-time restore, creating and restoring DB snapshots, CloudWatch metrics, event categories and subscriptions, SSL/TLS certificate bundles
- AWS EC2 User Guide: status checks, status check alarms, automatic instance recovery. AWS EBS User Guide: Amazon EBS snapshots
- AWS Backup Developer Guide: restore testing. Amazon Route 53 Developer Guide: health check values, monitoring health checks. Amazon CloudWatch User Guide: metrics collected by the CloudWatch agent
- AWS CLI v2 command reference (docs.aws.amazon.com/cli/latest/reference/): rds, ec2 and cloudwatch commands used above
Stay updated with new posts
Get notified when I publish new articles about web development, system design, and AI. No spam, unsubscribe anytime.