> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apinizer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Restore

> In Apinizer platform, you can restore all system configurations, API proxy definitions, policy settings, and other data using backups taken from MongoDB database. Platform can perform data restore operations from backup files with mongorestore command and supports system recovery, data integrity, and disaster recovery scenarios.

## Importance of Restore

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

<CardGroup cols={2}>
  <Card title="Quick System Recovery" icon="bolt">
    In case of data loss or system failure, you can quickly make the system operational by restoring from backup.
  </Card>

  <Card title="Data Integrity" icon="shield">
    By restoring from backup, you can return your system to a specific point in time.
  </Card>

  <Card title="Test Environments" icon="flask">
    By restoring backups to test environments, you can perform test and development operations with real data.
  </Card>

  <Card title="Version Rollback" icon="code-branch">
    If problems occur after system update, you can restore from the backup of the previous version.
  </Card>

  <Card title="Disaster Recovery" icon="server">
    In large-scale system failures, you can ensure business continuity by restoring from backups.
  </Card>
</CardGroup>

## 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:

```bash mongorestore theme={null}
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         |

<Warning>
  When `--drop` parameter is used, existing collections are deleted and recreated. This operation cannot be undone, so it should be used carefully.
</Warning>

### Restore to Replica Set

Example command that restores to entire replica set without targeting Primary MongoDB server:

```bash mongorestore theme={null}
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:

```bash mongorestore theme={null}
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

<Warning>
  Restore operation is a critical operation and may affect existing data. Be sure to follow the steps below:
</Warning>

<Steps>
  <Step title="Backup File Check">
    Check the integrity of the backup file before performing restore.
  </Step>

  <Step title="Version Compatibility">
    Ensure that the backup file is compatible with Apinizer version.
  </Step>

  <Step title="Backup Current State">
    Always take a backup of the current state before performing restore.
  </Step>

  <Step title="Try in Test Environment">
    If possible, try the restore operation in a test environment first.
  </Step>

  <Step title="Plan Maintenance Window">
    Plan a maintenance window since the system will be unavailable during restore operation.
  </Step>
</Steps>

## Restore Best Practices

<CardGroup cols={2}>
  <Card title="Planning" icon="calendar">
    Plan and document the restore operation in advance.
  </Card>

  <Card title="Testing" icon="flask">
    Regularly perform restore tests.
  </Card>

  <Card title="Backup" icon="database">
    Take a backup of the current state before restore.
  </Card>

  <Card title="Version Control" icon="tag">
    Check version information in backup files.
  </Card>

  <Card title="Documentation" icon="file-lines">
    Document restore operations.
  </Card>

  <Card title="Monitoring" icon="chart-line">
    Verify that the system is working properly after restore.
  </Card>
</CardGroup>

## Detailed Information

You can review the [MongoDB documentation](https://docs.mongodb.com/manual/tutorial/restore-replica-set-from-backup/) for detailed information.
