2024-08-03 16:03:17 +02:00
---
title: Restore database from AWS S3
layout: default
parent: How Tos
2024-09-30 00:40:35 +02:00
nav_order: 6
2024-08-03 16:03:17 +02:00
---
2025-01-13 14:56:08 +01:00
# Restore Database from S3 Storage
2024-08-03 16:03:17 +02:00
2025-01-13 14:56:08 +01:00
To restore a MySQL database from a backup stored in S3, use the `restore` command and specify the backup file with the `--file` flag. The system supports the following file formats:
2024-08-03 16:03:17 +02:00
2025-01-13 14:56:08 +01:00
- `.sql` (uncompressed SQL dump)
- `.sql.gz` (gzip-compressed SQL dump)
- `.sql.gpg` (GPG-encrypted SQL dump)
- `.sql.gz.gpg` (GPG-encrypted and gzip-compressed SQL dump)
2024-08-03 16:03:17 +02:00
2025-01-13 14:56:08 +01:00
---
## Configuration Steps
1. **Specify the Backup File** : Use the `--file` flag to specify the backup file to restore.
2. **Set the Storage Type** : Add the `--storage s3` flag to indicate that the backup is stored in S3.
3. **Provide S3 Configuration** : Include the necessary AWS S3 credentials and configuration.
4. **Provide Database Credentials** : Ensure the correct database connection details are provided.
---
## Example: Restore from S3 Configuration
2024-08-03 16:03:17 +02:00
2025-01-13 14:56:08 +01:00
Below is an example `docker-compose.yml` configuration for restoring a database from S3 storage:
```yaml
2024-08-03 16:03:17 +02:00
services:
mysql-bkup:
2025-01-13 14:56:08 +01:00
# In production, lock your image tag to a specific release version
# instead of using `latest` . Check https://github.com/jkaninda/mysql-bkup/releases
# for available releases.
2024-08-03 16:03:17 +02:00
image: jkaninda/mysql-bkup
container_name: mysql-bkup
2024-08-10 10:50:00 +02:00
command: restore --storage s3 -d my-database -f store_20231219_022941.sql.gz --path /my-custom-path
2024-08-03 16:03:17 +02:00
volumes:
2025-01-13 14:56:08 +01:00
- ./backup:/backup # Mount the directory for local operations (if needed)
2024-08-03 16:03:17 +02:00
environment:
- DB_PORT=3306
- DB_HOST=mysql
- DB_NAME=database
- DB_USERNAME=username
- DB_PASSWORD=password
2025-01-13 14:56:08 +01:00
## AWS S3 Configuration
2024-08-03 16:03:17 +02:00
- AWS_S3_ENDPOINT=https://s3.amazonaws.com
- AWS_S3_BUCKET_NAME=backup
2025-01-13 14:56:08 +01:00
- AWS_REGION=us-west-2
2024-08-03 16:03:17 +02:00
- AWS_ACCESS_KEY=xxxx
- AWS_SECRET_KEY=xxxxx
2025-01-13 14:56:08 +01:00
## Optional: Disable SSL for S3 alternatives like Minio
- AWS_DISABLE_SSL=false
## Optional: Enable path-style access for S3 alternatives like Minio
- AWS_FORCE_PATH_STYLE=false
# Ensure the pg-bkup container is connected to the same network as your database
2024-08-03 16:03:17 +02:00
networks:
- web
2025-01-13 14:56:08 +01:00
2024-08-03 16:03:17 +02:00
networks:
web:
2024-08-04 11:42:07 +02:00
```
2025-01-13 14:56:08 +01:00
---
## Key Notes
- **Supported File Formats**: The restore process supports `.sql` , `.sql.gz` , `.sql.gpg` , and `.sql.gz.gpg` files.
- **S3 Path**: Use the `--path` flag to specify the folder within the S3 bucket where the backup file is located.
- **Encrypted Backups**: If the backup is encrypted with GPG, ensure the `GPG_PASSPHRASE` environment variable is set for automatic decryption.
- **S3 Alternatives**: For S3-compatible storage like Minio, set `AWS_DISABLE_SSL` and `AWS_FORCE_PATH_STYLE` as needed.
- **Network Configuration**: Ensure the `pg-bkup` container is connected to the same network as your database.