Skip to content

Commit

Permalink
Docs updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeliasi committed Aug 22, 2024
1 parent 80d069b commit 4b54903
Showing 1 changed file with 49 additions and 11 deletions.
60 changes: 49 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Database S3 Backups

# Database S3 backups
This script provides a simple all-in-one automated way to back up your databases to AWS S3.
This script provides a simple, automated way to back up your databases to AWS S3. It supports multiple database types and can be easily configured to run on a schedule.

[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/U_wjYd?referralCode=lukeliasi)

Expand All @@ -10,18 +10,42 @@ Supported databases:
- `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
- Define multiple databases of different types in your configuration
- Automatic backup process for all databases in one execution
- Backups can be initiated on script execution or scheduled using a cron job
- Backups are compressed to reduce file size

## Installation

1. Clone this repository
2. Install dependencies: `npm install`
3. Set up your `.env` file (see Configuration section)
4. Run the script: `npm run start`

## Usage

Standalone:

```bash
npm run start
```

or with Docker:

```bash
docker compose up --build
```

## How it Works

1. Define database connection URI strings and backup schedule
2. The script connects to the database(s) and performs a dump
3. The dump is compressed and uploaded to your AWS S3 Bucket
4. Dumps are cleaned up on the local file system

## Configuration

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

```
Expand All @@ -35,7 +59,7 @@ AWS_S3_ENDPOINT=<S3_ENDPOINT>
DATABASES="mysql://user:password@host:port/database,postgresql://user:password@host:port/database,mongodb://user:password@host:port"
```

### Environment variables
### Environment Variables

| Key | Description | Optional | Default Value |
|-------------------------|--------------------------|----------|---------------|
Expand All @@ -47,3 +71,17 @@ DATABASES="mysql://user:password@host:port/database,postgresql://user:password@h
| `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 | |

## FAQ

### Q: How do I backup local databases on the same server the script is running on?
A: If you're trying to backup databases that are running locally on the same server as this backup script, you may need to set the network mode to "host" in your Docker configuration. This allows the container to access the host's network stack directly. You can do this by adding `--network host` when running your Docker container, or by setting `network_mode: host` in your docker-compose.yml file.

Note: Using host network mode can have security implications, so only use it if necessary and understand the risks involved.

### Q: Why am I getting a "connection refused" error when trying to connect to my database?
A: This error can occur due to various reasons, including incorrect connection details, network issues, firewalls, VPN configurations, or database server status. Double-check your connection string, ensure network accessibility, verify firewall settings, and confirm the database server is running and accepting connections from your container's environment.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

0 comments on commit 4b54903

Please sign in to comment.