# How to decrypt a database backup

If you take MySQL or PostgreSQL backups with encryption enabled, you will have to decrypt the backup before the restore.

### Decrypting a backup

For this example, we assume the private key is named `my-key.pem` and the encrypted backup file is named `my-db-backup.sql.gz`.

{% hint style="danger" %}
In order to decrypt encrypted backups, you need the private key generated when you enabled the ecryption. If you don't have the key, the content of the backups is lost!
{% endhint %}

{% tabs %}
{% tab title="Linux" %}

```
cat my-db-backup.sql.gz | openssl smime -decrypt -inform DER -inkey my-key.pem | gunzip > my-db-backup.sql
```

{% endtab %}

{% tab title="MacOS" %}

```
cat my-db-backup.sql.gz | openssl smime -decrypt -inform DER -inkey my-key.pem | gunzip > my-db-backup.sql
```

{% endtab %}
{% endtabs %}

After running the command above, a new file `my-db-backup.sql` will be created with the decrypted database backup.
