2024-08-03 16:03:17 +02:00
---
title: Restore database from SSH
layout: default
parent: How Tos
2024-09-30 00:40:35 +02:00
nav_order: 7
2024-08-03 16:03:17 +02:00
---
2025-01-13 14:56:08 +01:00
# Restore Database from SSH Remote Server
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 on an SSH remote server, 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 ssh` flag to indicate that the backup is stored on an SSH remote server.
3. **Provide SSH Configuration** : Include the necessary SSH credentials and configuration.
4. **Provide Database Credentials** : Ensure the correct database connection details are provided.
---
## Example: Restore from SSH Remote Server Configuration
Below is an example `docker-compose.yml` configuration for restoring a database from an SSH remote server:
```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 ssh -d my-database -f store_20231219_022941.sql.gz --path /home/jkaninda/backups
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)
- ./id_ed25519:/tmp/id_ed25519 # Mount the SSH private key file
2024-08-03 16:03:17 +02:00
environment:
- DB_PORT=3306
2025-01-13 14:56:08 +01:00
- DB_HOST=mysql
2024-08-03 16:03:17 +02:00
- DB_NAME=database
- DB_USERNAME=username
- DB_PASSWORD=password
2025-01-13 14:56:08 +01:00
## SSH Configuration
- SSH_HOST_NAME=hostname
2024-08-03 16:03:17 +02:00
- SSH_PORT=22
- SSH_USER=user
- SSH_REMOTE_PATH=/home/jkaninda/backups
- SSH_IDENTIFY_FILE=/tmp/id_ed25519
2025-01-13 14:56:08 +01:00
## Optional: Use password instead of private key (not recommended)
2024-08-03 16:03:17 +02:00
#- SSH_PASSWORD=password
2025-01-13 14:56:08 +01:00
# Ensure the mysql-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:
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.
- **SSH Path**: Use the `--path` flag to specify the folder on the SSH remote server 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.
- **SSH Authentication**: Use a private key (`SSH_IDENTIFY_FILE` ) for SSH authentication instead of a password for better security.
- **Network Configuration**: Ensure the `mysql-bkup` container is connected to the same network as your database.