Backup/Restore Data
Backup and restore of data require the use of scripts introduced in Data Backup and Restore. The difference is that metadb backup and restore are executed in the metadb-0 container, engine backup and restore are executed in the master-0 container, and minio backup and restore are executed in the minio-0 container.
Note
In a k8s environment, only local backup methods are used, with backups defaulting to the /opt/hsdata/backup directory.
Preparations Before Data Recovery
Before recovering metadb and engine data, stop the hengshi-sense service to avoid affecting the data recovery results. This step can be ignored for minio data recovery.
- Example of stopping the hengshi-sense service.
kubectl -n hengshi scale --replicas=0 deployment hengshi-sense
Backup and Restore metadb
Follow the steps in the example to backup and restore metadb.
- Example of backing up metadb.
kubectl -n hengshi exec -it metadb-0 -- mkdir -p /opt/hsdata/backup
kubectl -n hengshi exec -it metadb-0 -- /opt/hengshi/bin/dbbackup.sh -m metadb -l /opt/hsdata/backup
- Example of restoring metadb.
kubectl -n hengshi exec -it metadb-0 -- /bin/bash ## Enter the metadb-0 container and perform the following operations
/opt/hengshi/bin/hengshi-sense-bin stop metadb single
sudo mv ${HSDATA}/pg_data ${HSDATA}/pg_data.old
/opt/hengshi/bin/hengshi-sense-bin init metadb single
/opt/hengshi/bin/hengshi-sense-bin start metadb single
/opt/hengshi/bin/dbrestore.sh -m metadb -l /opt/hsdata/backup -t metadb_backup.xx-xx-xx_xx:xx:xx.tar.gz
- After the data recovery is successful, confirm the correctness of the data, and then delete the historical old data.
kubectl -n hengshi exec -it metadb-0 -- sudo rm -rf ${HSDATA}/pg_data.old
Backup and Restore engine Data
Follow the steps in the example to perform backup and restore of engine data.
- Example of backing up engine data.
kubectl -n hengshi exec -it master-0 -- mkdir -p /opt/hsdata/backup
kubectl -n hengshi exec -it master-0 -- /opt/hengshi/bin/dbbackup.sh -m engine -l /opt/hsdata/backup
- Example of restoring engine data.
kubectl -n hengshi exec -it master-0 -- /bin/bash ## Enter the master-0 container and perform the following operations
/entrypoint.sh -m stopsystem
for host in ${MASTER} ${SEGMENTS};do ssh $host "sudo mv ${HSDATA}/engine-cluster ${HSDATA}/engine-cluster.old";done
/entrypoint.sh -m initsystem
/entrypoint.sh -m startsystem
/opt/hengshi/bin/dbrestore.sh -m engine -l /opt/hsdata/backup -t engine_backup.xx-xx-xx_xx:xx:xx.tar.gz
- After the data recovery is successful, confirm the correctness of the data, and then delete the historical old data.
kubectl -n hengshi exec -it master-0 -- for host in ${MASTER} ${SEGMENTS};do ssh $host "sudo rm -rf ${HSDATA}/engine-cluster.old";done
Backup and Restore MinIO
Follow the steps in the example to backup and restore MinIO.
- Example of backing up MinIO.
kubectl -n hengshi exec -it minio-0 -- mkdir -p /opt/hsdata/backup
kubectl -n hengshi exec -it minio-0 -- /opt/hengshi/bin/dbbackup.sh -m minio -l /opt/hsdata/backup
- Example of restoring MinIO.
kubectl -n hengshi exec -it minio-0 -- /bin/bash ## Enter the metadb-0 container and perform the following operations
/opt/hengshi/bin/hengshi-sense-bin stop minio single
sudo mv ${HSDATA}/minio-data ${HSDATA}/minio-data.old
/opt/hengshi/bin/dbrestore.sh -m minio -l /opt/hsdata/backup -t minio_backup.xx-xx-xx_xx:xx:xx.tar.gz
/opt/hengshi/bin/hengshi-sense-bin start minio single
- After the data recovery is successful, confirm the correctness of the data, and then delete the historical old data.
kubectl -n hengshi exec -it minio-0 -- sudo rm -rf ${HSDATA}/minio-data.old
Operations After Data Recovery
After the metadb and engine data recovery is completed, continue to restore the hengshi-sense service. This step can be ignored for minio data recovery.
- Example of restoring the hengshi-sense service.
hs_pods_num= #Number of hengshi-sense service instances, fill in according to the number before stopping
kubectl -n hengshi scale --replicas=${hs_pods_num} deployment hengshi-sense