Question about backup the database


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

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(...) convenience function provides many options depending on your needs.

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

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

Hi @joe00z

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

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

It works fine. Thank you very much.