---
title: "Deploy Database S3 backups"
description: "A simple script to automatically back up multiple databases to S3."
category: "Automation"
url: https://railway.com/deploy/U_wjYd
---

# Deploy Database S3 backups

A simple script to automatically back up multiple databases to S3.

**[Deploy Database S3 backups on Railway](https://railway.com/template/U_wjYd)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/U_wjYd/manifest.json

- **Creator:** Luke Liasi's Projects
- **Category:** Automation
- **Total deploys:** 54

## Template content

### database-backups-s3

- **Source:** https://github.com/lukeliasi/database-backups-s3

## Documentation


# Database S3 backups
This script provides a simple all-in-one automated way to back up your databases to AWS S3.

Supported databases:
- `postgres`
- `mysql`
- `mongodb`

## Features
- Define multiple databases of different types in your configuration, and the script will automatically handle the backup process for all of them in one execution.
- Backups can be initiated either upon the script execution or on a scheduled basis using a cron job. 
- Backups are compressed to reduce file size.

## How it works 
1. Define database connection URI strings for each database you want backed up and the backup schedule 
2. The script will connect to the database(s) and do a dump
3. The dump is compressed and uploaded to your defined AWS S3 Bucket
4. Finally, the dumps are cleaned up on the local file system


## Configuration
Create a `.env` file in the root directory with the following variables:

```
RUN_ON_STARTUP=true
CRON=0 0 * * *
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_S3_BUCKET=
AWS_S3_REGION=
AWS_S3_ENDPOINT=
DATABASES="mysql://user:password@host:port/database,postgresql://user:password@host:port/database,mongodb://user:password@host:port"
```

### Environment variables

| Key                     | Description              | Optional | Default Value |
|-------------------------|--------------------------|----------|---------------|
| `DATABASES`             | Comma-separated connection strings list of database URIs that should be backed up. | No | `[]`|
| `RUN_ON_STARTUP`        | Boolean value that indicates if the script should run immediately on startup. | Yes | `false` |
| `CRON`                  | Cron expression for scheduling when the backup job will run for all databases. See [Crontab.guru](https://crontab.guru/) for help setting up schedules. | Yes | |
| `AWS_ACCESS_KEY_ID`     | [AWS access key ID](https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys). | No | |
| `AWS_SECRET_ACCESS_KEY` | [AWS secret access key](https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys). | No | |
| `AWS_S3_BUCKET`         | [Name of the S3 bucket](https://docs.aws.amazon.com/AmazonS3/latest/dev/Welcome.html). | No | |
| `AWS_S3_REGION`         | [Region of the S3 bucket](https://docs.aws.amazon.com/general/latest/gr/rande.html). | No | |
| `AWS_S3_ENDPOINT`       | [Endpoint for the S3 service](https://docs.aws.amazon.com/general/latest/gr/s3.html). | No | |

## Similar templates

- [N8N Main + Worker](https://railway.com/deploy/n8n-main-worker) — Deploy and Host N8N with Inactive worker.
- [Evolution API with n8n](https://railway.com/deploy/evolution-api-with-n8n) — Automate WhatsApp workflows with Evolution API, n8n, and Postgres.
- [Postgres Backup](https://railway.com/deploy/postgres-s3-backups) — Cron-based PostgreSQL backup to bucket storage

Open this page in a browser: https://railway.com/deploy/U_wjYd
