Backup

Because Apinizer stores all its configurations in the MongoDB database, regular database backups are necessary. These backups allow you to restore all configurations in the event of system failure or data loss.

Apinizer works with the Replica Set MongoDB database. This should be taken into account when backing up via the 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
POWERSHELL

It is recommended to use the backup file name based on the backup date and Apinizer version.
This allows you to:

  • Easily identify which backup belongs to which system version.
  • Version incompatibilities are prevented during restore operations.
  • Easier management of archived backups.


If you do not want to include parts that may take up a lot of space, such as application logs or audit logs, you can separate them with the following command:

 --excludeCollection apinizer_log --excludeCollection audit_event

However, this process is not recommended as it will result in data redundancy.

For detailed information, you can review the MongoDB documentation.



Restore

To restore Apinizer configuration data from a backup, you use the backup files you created. This is done using the "mongorestore" command in the Linux shell.

For detailed information, you can review the MongoDB documentation.


A 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
CODE


Example command to restore all replicas without targeting the 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
CODE


If you backed up just a single Collection and not the entire database, you can 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
POWERSHELL