Back up and restore
n8n keeps your workflows, credentials and execution history in its database, and its encryption key in Secrets Manager. If you lose either one, you lose the ability to read your credentials. A backup protects against a deleted database. A copy in a second region protects against the loss of a whole region.
This guide shows how to turn backups on, how the copy works, and how to restore from it. You need a deployment that uses a database or EFS, and an account where the CDK is bootstrapped in the copy region. The terms are in concepts.
Turn backups on
backup:
kind: aws-backup
retention_days: 14
cross_region: eu-west-1 # optionalThe sample backup-cross-region is a complete file. cross_region needs backup.kind: aws-backup and a region other than the deployment's (rule T19).
How the copy works
backup.cross_region needs backup.kind: aws-backup and a region other than the deployment's (rules T19). The deployment then gets a stack <name>-backup-copy in that region, with a KMS key (rotation on) and a backup vault. The daily rule of the backup plan copies each recovery point (Aurora or RDS, EFS) to that vault and keeps the copy for backup.retention_days. The n8n encryption-key secret that n8n-on-aws creates is replicated to the same region, encrypted with that key. An existing encryption key is not replicated by this tool, and T19 warns about it: replicate that secret yourself (aws secretsmanager replicate-secret-to-regions).
The vault, its key and its recovery points are retained when the stacks are deleted, like the encryption-key secret. n8n-on-aws destroy prints what remains. The plan's own vault in the deployment region stays too when it holds a recovery point. n8n-on-aws cleanup deletes the helper log groups in the copy region. To remove the vaults on purpose, delete the recovery points (aws backup list-recovery-points-by-backup-vault, then aws backup delete-recovery-point), then the vault (aws backup delete-backup-vault), then schedule the key for deletion. n8n-on-aws cleanup --purge deletes the replicated secret with the original; the vaults and the key stay manual.
Restore runbook
Use it when the deployment region is lost or its vault is gone. Every step runs in the cross_region region, and the CDK must be bootstrapped there.
- Find the latest recovery point of the database:
aws backup list-recovery-points-by-backup-vault --backup-vault-name <name>-copy --region <cross_region>. - Create what the restore needs in that region: a subnet group over two subnets and a security group. The copy region may have no default VPC.
- Start the restore (
aws backup start-restore-job --resource-type Aurora) with the metadata ofaws backup get-recovery-point-restore-metadata, and change three values:DBClusterIdentifierto a new name,DBSubnetGroupNameandVpcSecurityGroupIdsto those of step 2, andKmsKeyIdto the copy key (alias/<name>-backup-copy). The metadata names the key of the lost region, which the restore cannot use. The role of the backup plan can restore: it carries the restore policy. Then add an instance to the restored cluster. - Reset the master password with
aws rds modify-db-cluster --master-user-password, and keep it in a Secrets Manager secret in that region. The database credentials secret<name>/databaseis not replicated, so the old password is lost with the region. - Check that the replicated secret
<name>/n8n-encryption-keyexists in that region and holds the value of the lost deployment. n8n cannot read its stored credentials with any other key. - Deploy n8n against the restored cluster: set
aws.regionto the new region,database.kind: externalwith the restored endpoint, the secret of step 4 andsecurity_group_idof the cluster, andn8n.encryption_key: {kind: existing, secret: <name>/n8n-encryption-key}.T19does not apply, becausebackup.cross_regionis left out. - Open n8n, check a workflow and a credential, then re-point DNS.
The copy is a recovery point, so the restore returns the data of the last completed copy, at most one day old with the daily schedule.