Restore
Importance of Restore
Restore operation is a critical operation in terms of system recovery and data integrity:
In case of data loss or system failure, you can quickly make the system operational by restoring from backup.
By restoring from backup, you can return your system to a specific point in time.
By restoring backups to test environments, you can perform test and development operations with real data.
If problems occur after system update, you can restore from the backup of the previous version.
In large-scale system failures, you can ensure business continuity by restoring from backups.
MongoDB Restore Operation
To restore Apinizer configuration data from backup, the backup files you created are used. This operation is performed with mongorestore command on Linux shell.
Basic Restore Command
The previously taken backup file can be restored using the following command:
mongorestore \
--drop \
--host=<PRIMARY_MONGODB_IP> \
--port=<PRIMARY_MONGODB_PORT> \
--username=apinizer \
--authenticationDatabase=admin \
--gzip \
--archive=/home/apinizer/apinizer-backup-v<CURRENT_VERSION>--<BACKUP_DATE>--01.archive
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
--drop | boolean | No | Delete and recreate existing collections |
--host | string | Yes | IP address of Primary MongoDB server |
--port | number | Yes | MongoDB port number |
--username | string | Yes | MongoDB username |
--authenticationDatabase | string | No | Authentication database (default: admin) |
--gzip | boolean | No | Compressed backup file |
--archive | string | Yes | Path of backup file to be restored |
When --drop parameter is used, existing collections are deleted and recreated. This operation cannot be undone, so it should be used carefully.
Restore to Replica Set
Example command that restores to entire replica set without targeting Primary MongoDB server:
mongorestore \
--drop \
--host apinizer-replicaset/10.0.0.1:25080,10.0.0.2:25080,10.0.0.3:25080 \
--username apinizer \
--password "123456" \
--gzip \
--archive=/home/apinizer/apinizer-backup-v2024092--20241231--01.archive
Single Collection Restore
If only a single collection is backed up, not the entire database, to restore it:
mongorestore \
--drop \
--host 10.0.0.1 \
--port 25080 \
--authenticationDatabase "admin" \
-d apinizerdb \
-u apinizer \
-p "123456" \
--collection=api_proxy \
/home/apinizer/apinizerdb/api_proxy.bson
Precautions Before Restore
Restore operation is a critical operation and may affect existing data. Be sure to follow the steps below:
Check the integrity of the backup file before performing restore.
Ensure that the backup file is compatible with Apinizer version.
Always take a backup of the current state before performing restore.
If possible, try the restore operation in a test environment first.
Plan a maintenance window since the system will be unavailable during restore operation.
Restore Best Practices
Plan and document the restore operation in advance.
Regularly perform restore tests.
Take a backup of the current state before restore.
Check version information in backup files.
Document restore operations.
Verify that the system is working properly after restore.
Detailed Information
You can review the MongoDB documentation for detailed information.