# Question about backup the database

**URL:** <https://discuss.zetetic.net/t/question-about-backup-the-database/5470>\
**Category:** SQLCipher\
**Created:** [June 23, 2022, 8:13am UTC](https://discuss.zetetic.net/t/question-about-backup-the-database/5470 "2022-06-23T08:13:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe00z](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@joe00z](https://discuss.zetetic.net/u/joe00z)\
**Post date:** [June 23, 2022, 8:13am UTC](https://discuss.zetetic.net/t/question-about-backup-the-database/5470/1 "2022-06-23T08:13:05Z")

</div>

Hi,

I have a sqlite3 database and it is encrypted with SQLCipher now.  
Originally, the backup of the database is using “dump”.  
With the encrypted database, when I try to perform a dump, the dump file shows  
/\*\*\*\* ERROR: (26) file is encrypted or is not a database \*\*\*\*\*/  
May I know if there is a proper way to perform a dump with the encrypted database?

Also, I followed the step in [Cannot perform a backup from encrypted to encrypted](https://discuss.zetetic.net/t/cannot-perform-a-backup-from-encrypted-to-encrypted/5051). When I executed the line ATTACH DATABASE ‘{backupPath}’ AS encrypted KEY ‘{databaseKey}’;, it is showing the error:  
Error: stepping, file is not a database (26)

May I know how can I perform the backup with the encrypted database? Thank you.

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [June 24, 2022, 1:34pm UTC](https://discuss.zetetic.net/t/question-about-backup-the-database/5470/2 "2022-06-24T13:34:27Z")

</div>

Hi @joe00z

Are you needing to get the SQL statements representing the database, or just generally need to create another copy of the database? If the latter, utilizing the [`sqlcipher_export(...)`](https://www.zetetic.net/sqlcipher/sqlcipher-api/#sqlcipher_export) convenience function provides many options depending on your needs.

> [@joe00z](#):
>
> ATTACH DATABASE ‘{backupPath}’ AS encrypted KEY ‘{databaseKey}’;

It appears the quotes you are using in the example are not single straight quotes, but rather an opening and closing curly single quotes. This will not work correctly and may be the cause of your error. You can either use a single straight quotes (i.e., `'`), or the parameter placeholder such as `?`.

---

<div class="post-metadata">

**Author:** ![joe00z](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@joe00z](https://discuss.zetetic.net/u/joe00z)\
**Post date:** [June 25, 2022, 5:58pm UTC](https://discuss.zetetic.net/t/question-about-backup-the-database/5470/3 "2022-06-25T17:58:52Z")

</div>

Thank you for the suggestion. I would like to get the SQL statements representing the database. May I know how to get it? Thanks.

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [June 27, 2022, 2:00pm UTC](https://discuss.zetetic.net/t/question-about-backup-the-database/5470/4 "2022-06-27T14:00:35Z")

</div>

Hi @joe00z

If you have access to a SQLCipher command line shell you can use the standard `.dump` command after providing the key:

```auto
./sqlcipher foo.db
sqlite> PRAGMA key = '<YourKeyHere>';
sqlite> .output 'output.sql'
sqlite> .dump

```

Alternatively, you can use the `sqlcipher_export` function linked above to export the database to plaintext, then you can use the standard SQLite command line interface to invoke `.dump` on the plaintext database.

---

<div class="post-metadata">

**Author:** ![joe00z](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@joe00z](https://discuss.zetetic.net/u/joe00z)\
**Post date:** [June 29, 2022, 9:39am UTC](https://discuss.zetetic.net/t/question-about-backup-the-database/5470/5 "2022-06-29T09:39:01Z")

</div>

It works fine. Thank you very much.
