0

Currently, our app is using Room SQLite.

We need to let user to create application data backup, and export them as a single zip file.

Direct File Copy

I was wondering, is it safe, to perform direct File copy on application SQLite file to a temporary folder, for further zipping purpose? The reason I ask so is, I notice that sometimes the application database instead of appearing as single file like local-backup, it will have 2 additional files named local-backup-shm and local-backup-wal.

Read and Write to a temporary SQLite DB

Or, I should just create a temporary empty database, use Room to read application data and write to the temporary database? Then, zipping will be performed on the temporary database?

Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875

1 Answers1

0

Copying the file is sufficient. That will copy the entire db.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • How about additional files like `*-shm` and `*-wal`? – Cheok Yan Cheng Apr 23 '19 at 06:27
  • Those should be empty if the db isn't in use. If it is in use, you need to be careful about backing up anyway since you could miss a write that was in progress. Checkpoint the database first to ensure it isn't an issue. That will clean out the wal file (and the shm is just an index for the wal). See https://stackoverflow.com/questions/51535178/how-to-manually-perform-checkpoint-in-sqlite-android for how to do that. – Gabe Sechan Apr 23 '19 at 06:33