Backup
Apinizer works with Replica Set MongoDB database. This situation should be taken into account when taking backup from MongoDB server.
mongodump \
--host=<PRIMARY_MONGODB_IP> \
--port=<PRIMARY_MONGODB_PORT> \
--authenticationDatabase admin \
--username apinizer \
--password <MONGO_PASSWORD> \
--db <DATABASE_NAME> \
--gzip \
--archive=/home/apinizer/apinizer-backup--v<CURRENT_VERSION>--<BACKUP_DATE>--01.archive
It is recommended to use the date when backup was taken and Apinizer version information in backup file naming. This way:
- It is easy to understand which backup belongs to which system version
- Version incompatibilities are prevented in restore operations
- Management of archived backups is facilitated
If application logs or audit logs that may take up high space are not desired to be included, they can be separated with this command:--excludeCollection apinizer_log --excludeCollection audit_eventHowever, this operation will lead to data not being backed up, so it is not recommended.
You can review the MongoDB documentation for detailed information.
Restore
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
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
You can review the MongoDB documentation for detailed information.