
Deploy MYSQL & MONGODB Backup to S3 Service
Quick backup your Mysql or MongoDB to any S3 service.
mysql-backup-to-s3
Just deployed
mysql-mongodb-backup-to-s3
Quick Backup your MySQL and MongoDB to any S3 Service
MySQL & MongoDB Backup to S3
A lightweight Node.js service that creates compressed backups of MySQL and MongoDB databases and uploads them to any S3-compatible object storage.
The service connects directly to MySQL/MongoDB, generates dumps, compresses them using gzip, and stores the backups as .sql.gz or .gz files in an S3 bucket. It is designed to run on Railway but can be deployed anywhere.
Features
- Supports MySQL and MariaDB
- Supports MongoDB
- Uploads backups to any S3-compatible storage
- Creates compressed
.sql.gz(MySQL) and.gz(MongoDB) backups - Can back up a single database or all databases
- Stateless and easy to deploy
- Works well with cron-based scheduling (e.g. Railway cron jobs)
How It Works
MySQL
- Connects to a MySQL database
- Generates SQL dump(s) for one or more databases
- Compresses the dump using gzip
- Uploads the backup file to an S3 bucket
- Cleans up temporary files
MongoDB
- Connects to MongoDB using a connection URI
- Generates a dump for the specified database (or all non-system databases)
- Compresses the dump using gzip
- Uploads the backup file to an S3 bucket
- Cleans up temporary files
Each backup is stored with a timestamped filename.
Environment Variables
S3 Configuration
-
AWS_ACCESS_KEY_ID
S3 access key ID -
AWS_SECRET_ACCESS_KEY
S3 secret access key -
AWS_S3_BUCKET
Target S3 bucket name -
AWS_S3_REGION
S3 bucket region -
AWS_S3_ENDPOINT(optional)
Custom endpoint for S3-compatible providers (MinIO, Backblaze, etc.)
MySQL Configuration
-
MYSQL_ENABLED
Enable MySQL backup (trueto enable, default:true) -
BACKUP_DATABASE_HOST
Database host -
BACKUP_DATABASE_PORT
Database port -
BACKUP_DATABASE_USER
Database user -
BACKUP_DATABASE_PASSWORD
Database password -
BACKUP_DATABASE_NAME(optional)
Database name to back up
Leave empty to back up all databases (excluding system databases)
MongoDB Configuration
-
MONGODB_ENABLED
Enable MongoDB backup (trueto enable, default:false) -
MONGODB_URI(required when MongoDB is enabled)
MongoDB connection string
If the URI includes a database name it will be backed up; otherwise all non-system databases are backed up
Example:mongodb://user:password@host:27017/mydb
Scheduling & Debug
-
BACKUP_CRON_SCHEDULE
Cron schedule for automatic backups
Default:0 5 * * * -
DEBUG(optional)
Enable verbose logging (1to enable)
Deployment
Railway (Recommended)
- Create a new Railway project
- Deploy this repository
- Add the required environment variables
- (Optional) Configure a Railway cron job using
BACKUP_CRON_SCHEDULE
Manual
npm install
npm run build
node dist/index.js
Template Content
mysql-backup-to-s3
poziomekk/mysql-mongodb-backup-to-s3AWS_S3_BUCKET
The S3 bucket where the backups will be stored. (only name)
AWS_S3_REGION
The AWS region where the S3 bucket is located. (try auto)
MYSQL_ENABLED
Enable MySQL backup. (true/false)
AWS_S3_ENDPOINT
S3 endpoint URL, withOUT bucket name.
MONGODB_ENABLED
Enable MongoDB backup. (true/false)
AWS_ACCESS_KEY_ID
The AWS access key ID for accessing S3.
AWS_SECRET_ACCESS_KEY
The AWS secret access key associated with the access key ID.
