---
url: /v6.2/en-us/docker-backup-restore.md
---
## Backup Data

Backing up and restoring data requires using the scripts introduced in [Data Backup and Restore](backup-restore.md), with the distinction that the following operations are performed within the container.

The metadb backup is executed in the **hengshi-metadb** container.

The engine backup and restore are executed in the **hengshi-engine** container.

The minio backup and restore are executed in the **hengshi-minio** container.

> \[!CAUTION] Please Note
> In the Docker environment, only the local backup method is used, and backups are stored in the backup directory under HSHOME configured in .env. The default path is docker-compose-x.x/hsdata/backup.
> After restoring the data, please verify the correctness of the data before deleting the old data!

### Backup metadb

```shell
# Enter the metadb container and create a backup directory
docker exec -it hengshi-metadb mkdir -p /opt/hsdata/backup 
# Start the backup
docker exec -it hengshi-metadb /opt/hengshi/bin/dbbackup.sh -m metadb -l /opt/hsdata/backup -t sql.gz
```

### Restore metadb

* Stop all services

```shell
docker-compose down
```

* Rename the old data directory

```shell
sudo mv ${HSHOME}/hsdata/pg_data ${HSHOME}/hsdata/pg_data.old
```

> \[!CAUTION] Please note
> ${HSHOME} is a sample variable and cannot be directly copied and pasted! Please replace it with your actual deployment directory.
>
> For example:
>
> If hengshi is deployed in /data/docker-compose-6.0,
> the actual path would be sudo mv /data/docker-compose-6.0/hsdata/pg_data /data/docker-compose-6.0/hsdata/pg_data.old.

* Reinitialize the new metadb data and perform backup import

```shell
docker-compose run --rm metadb init metadb
docker-compose up -d metadb
docker exec -it hengshi-metadb /opt/hengshi/bin/dbrestore.sh -m metadb -l /opt/hsdata/backup -t metadb_backup.xx-xx-xx_xx-xx-xx
docker-compose down
```

* After metadb is successfully restored, restart the system.

```shell
docker-compose up -d
```

* After verifying normal operations, delete the old data.

```shell
docker exec -it hengshi-metadb bash -c "rm /opt/hsdata/pg_data.old -rf"
```

### Backup and Restore Engine Data

```shell
docker exec -it hengshi-engine mkdir -p /opt/hsdata/backup
docker exec -it hengshi-engine /opt/hengshi/bin/dbbackup.sh -m engine -l /opt/hsdata/backup
```

### Restore Engine

Stop all services (or you can stop only the Hengshi service)

```shell
docker-compose down
```

Rename the old data directory

```shell
sudo mv ${HSHOME}/hsdata/engine-cluster ${HSHOME}/hsdata/engine-cluster.old
```

> \[!CAUTION] Please note
> ${HSHOME} is a placeholder variable and cannot be directly copied and pasted! Replace it with your actual deployment directory.
>
> For example:
>
> If Hengshi is deployed in /data/docker-compose-5.1,
> the actual path would be:
> sudo mv /data/docker-compose-5.1/hsdata/engine-cluster /data/docker-compose-5.1/hsdata/engine-cluster.old

3. Reinitialize new engine data and perform backup import

```shell
docker-compose run --rm engine init engine
docker-compose up -d engine
docker exec -it hengshi-engine /opt/hengshi/bin/dbrestore.sh -m engine -l /opt/hsdata/backup -t engine_backup.xx-xx-xx_xx:xx:xx.tar.gz
docker-compose down
```

* After the engine is successfully restored, restart the system.

```shell
docker-compose up -d
```

* After confirming the business is functioning normally, delete the old data.

```shell
docker exec -it hengshi-engine bash -c "rm /opt/hsdata/engine-cluster.old -rf"
```

### Backup minio

```shell
docker exec -it hengshi-minio mkdir -p /opt/hsdata/backup
docker exec -it hengshi-minio /opt/hengshi/bin/dbbackup.sh -m minio -l /opt/hsdata/backup
```

### Restore Minio

Stop all services (or you can choose to stop only the HENGSHI service)

```shell
cd docker-compose-x.x
docker-compose down
```

Rename the old data directory

```shell
sudo mv ${HSHOME}/hsdata/minio-data ${HSHOME}/hsdata/minio-data.old
```

> \[!CAUTION] Please note
> ${HSHOME} is a sample variable and cannot be directly copied and pasted! Please replace it with your actual deployment directory.
>
> For example:
>
> If HENGSHI is deployed in /data/docker-compose-5.1,
> the actual path would be sudo mv /data/docker-compose-5.1/hsdata/minio-data /data/docker-compose-5.1/hsdata/minio-data.old.

Minio does not require initialization; you can directly import the backup after starting it.

```shell
docker-compose up -d minio
docker exec -it hengshi-minio /opt/hengshi/bin/dbrestore.sh -m minio -l /opt/hsdata/backup -t minio_backup.xx-xx-xx_xx:xx:xx.tar.gz
docker-compose down
```

* After Minio is successfully restored, restart the system.

```shell
docker-compose up -d
```

* After confirming the business is functioning normally, delete the old data.

```shell
docker exec -it hengshi-minio bash -c "rm /opt/hsdata/minio-data.old -rf"
```
