# 4.3.6.5 Resetting a server environment

### Reset a **development,** **qa and staging** environment

The **Reset environment** Github Action can be used to clear a **development,** **qa and staging** environment of all data. This is useful during testing of environments where you may have made test registrations.

<figure><img src="https://114323470-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl7Cjlh2y2hlCBlt6R76C%2Fuploads%2FS9wwK7W20HCSfGekBB8J%2FScreenshot%202024-11-14%20at%2007.26.56.png?alt=media&#x26;token=caa32c5e-9405-446e-84c5-8efe7c8aeac8" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
After resetting your environment, it contains no data at all.  It must be [seeded](https://documentation.opencrvs.org/v1.5/setup/3.-installation/3.3-set-up-a-server-hosted-environment/3.3.6-deploy-automated-and-manual/4.3.6.2-seeding-a-server-environment) again,
{% endhint %}

### Reset a **production** environment

Perhaps you need to clear production after completing a [test that backup is working successfully ](https://documentation.opencrvs.org/v1.5/setup/3.-installation/3.3-set-up-a-server-hosted-environment/4.3.7-backup-and-restore)in readiness for going live.  Or perhaps you need to [restore a previous backup](https://documentation.opencrvs.org/v1.5/setup/3.-installation/3.3-set-up-a-server-hosted-environment/4.3.7-backup-and-restore/4.3.7.1-restoring-a-backup) onto production for some other reason.  In these scenarios, you would be required to reset your production environment.

{% hint style="danger" %}
To protect you from accidentally resetting a **production** environment, we do not provide an action for this.  As part of our **Pre-Deployment Checklist**, perhaps you have made test registrations on production and are required to clear it before going live.  The following explains the steps required.  These are the manual steps that the Reset Environment action performs in an automated way.
{% endhint %}

1. You need the REPLICAS, ELASTICSEARCH\_ADMIN\_PASSWORD, MONGODB\_ADMIN\_USER, MONGODB\_ADMIN\_PASSWORD, MINIO\_ROOT\_USER and MINIO\_ROOT\_PASSWORD secrets for the production environment.  You created and stored these in your password manager in this [step](https://documentation.opencrvs.org/v1.5/setup/3.-installation/3.3-set-up-a-server-hosted-environment/4.3.4-create-a-github-environment).
2. SSH into your production environment manager node and run this command on your server to set these environment variables in your terminal session.

```
export ELASTICSEARCH_ADMIN_USER=elastic \
export ELASTICSEARCH_ADMIN_PASSWORD=<enter the appropriate secret here> \
export MONGODB_ADMIN_USER=<enter the appropriate secret here> \
export MONGODB_ADMIN_PASSWORD=<enter the appropriate secret here> \
export MINIO_ROOT_USER=<enter the appropriate secret here> \
export MINIO_ROOT_PASSWORD=<enter the appropriate secret here> \
export REPLICAS=<enter the appropriate secret here>
```

3. Run the following command to clear the data:

```
bash /opt/opencrvs/infrastructure/clear-all-data.sh $REPLICAS
```

4. All the databases are now empty but some database migrations must run to prepare them for re-seeding or restoring a backup.  Run this command to migrate the databases:

```yaml
/opt/opencrvs/infrastructure/run-migrations.sh
```

5. Run this command to clear your terminal session of the history of any exported secrets (security step)

```
history -c
history -w
```

Your production environment is now ready for re-seeding / restoration.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.opencrvs.org/v1.5/setup/3.-installation/3.3-set-up-a-server-hosted-environment/3.3.6-deploy-automated-and-manual/4.3.6.5-resetting-a-server-environment.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
