Skip to main content

Importance of Restore

Restore operation is a critical operation in terms of system recovery and data integrity:

Quick System Recovery

In case of data loss or system failure, you can quickly make the system operational by restoring from backup.

Data Integrity

By restoring from backup, you can return your system to a specific point in time.

Test Environments

By restoring backups to test environments, you can perform test and development operations with real data.

Version Rollback

If problems occur after system update, you can restore from the backup of the previous version.

Disaster Recovery

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
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:
ParameterTypeRequiredDescription
--dropbooleanNoDelete and recreate existing collections
--hoststringYesIP address of Primary MongoDB server
--portnumberYesMongoDB port number
--usernamestringYesMongoDB username
--authenticationDatabasestringNoAuthentication database (default: admin)
--gzipbooleanNoCompressed backup file
--archivestringYesPath 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
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
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:
1

Backup File Check

Check the integrity of the backup file before performing restore.
2

Version Compatibility

Ensure that the backup file is compatible with Apinizer version.
3

Backup Current State

Always take a backup of the current state before performing restore.
4

Try in Test Environment

If possible, try the restore operation in a test environment first.
5

Plan Maintenance Window

Plan a maintenance window since the system will be unavailable during restore operation.

Restore Best Practices

Planning

Plan and document the restore operation in advance.

Testing

Regularly perform restore tests.

Backup

Take a backup of the current state before restore.

Version Control

Check version information in backup files.

Documentation

Document restore operations.

Monitoring

Verify that the system is working properly after restore.

Detailed Information

You can review the MongoDB documentation for detailed information.