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

# Backup

> Apinizer platform stores all configurations, API proxy definitions, policy settings, user information, and system configurations in MongoDB database. Therefore, regular backup of MongoDB database is critical. Platform can perform database backup operations with mongodump command and prevent version incompatibilities by storing version information in backup files.

## Importance of Backup

Backup operation plays a vital role in terms of system security and data integrity:

<CardGroup cols={2}>
  <Card title="Preventing Data Loss" icon="shield">
    Protects your data in case of system failure, hardware error, or accidentally performed deletion operations.
  </Card>

  <Card title="Quick Recovery" icon="bolt">
    In case of possible data loss, you can quickly restore from backup and make your system operational in a short time.
  </Card>

  <Card title="Version Control" icon="code-branch">
    Thanks to backups taken at different times, you can store different versions of your system and revert when necessary.
  </Card>

  <Card title="Business Continuity" icon="chart-line">
    Ensures business continuity in critical systems and minimizes the impact of possible interruptions.
  </Card>
</CardGroup>

## MongoDB Backup Operation

<Warning>
  Apinizer works with Replica Set MongoDB database. This situation should be taken into account when taking backup from MongoDB server.
</Warning>

### Backup Command

MongoDB database can be backed up using the following command:

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

**Parameters:**

| Parameter                  | Type    | Required | Description                                        |
| -------------------------- | ------- | -------- | -------------------------------------------------- |
| `--host`                   | string  | Yes      | IP address of Primary MongoDB server               |
| `--port`                   | number  | Yes      | MongoDB port number                                |
| `--authenticationDatabase` | string  | No       | Authentication database (default: `admin`)         |
| `--username`               | string  | Yes      | MongoDB username                                   |
| `--password`               | string  | Yes      | MongoDB password                                   |
| `--db`                     | string  | Yes      | Database name to be backed up                      |
| `--gzip`                   | boolean | No       | Compresses backup file                             |
| `--archive`                | string  | Yes      | Path and file name where backup file will be saved |

### Backup File Naming

It is recommended to use the **date** when backup was taken and **Apinizer version information** in backup file naming.

<Info>
  **Recommended File Name Format:**
  `apinizer-backup--v<CURRENT_VERSION>--<BACKUP_DATE>--01.archive`

  Thanks to this format:

  * 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
</Info>

### Excluding Collections

<Warning>
  **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_event`

  However, this operation will lead to data not being backed up, so it is not recommended.
</Warning>

## Backup Best Practices

<CardGroup cols={2}>
  <Card title="Regular Backup" icon="calendar">
    Take backups at regular intervals (daily, weekly)
  </Card>

  <Card title="Automation" icon="gear">
    Automate backup operations (cron job, scheduled task)
  </Card>

  <Card title="Store in Different Locations" icon="server">
    Store backups in different physical locations
  </Card>

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

  <Card title="Version Information" icon="tag">
    Always include version information in backup files
  </Card>

  <Card title="Security" icon="lock">
    Store backup files securely and apply access control
  </Card>
</CardGroup>

## Detailed Information

You can review the [MongoDB documentation](https://docs.mongodb.com/manual/reference/program/mongodump/) for detailed information.
