My Backup Lost Every Photo

I built a backup button for an offline mood tracker.

It exported data to a JSON file. Users could save it and move it to a new phone. It seemed perfect.

Then I changed the app package ID. I tried a fresh install on a new device and restored the backup.

The text entries came back. Every photo was gone.

I realized my mistake. The backup was not a real backup. It was just a list of pointers to files that no longer existed.

The app stored photos on the disk. The database held the file path.

The path looked like this: file:///data/user/0/com.example.app/files/entry_media/image.jpg

When I exported the JSON, I only saved that path. On the same device, the import works because the files are still there.

On a new device, those paths point to nothing. The user sees broken thumbnails and thinks the app deleted their memories.

If your export only carries file paths, you do not have a portable backup. You have a backup that only works on the machine that does not need one.

A real backup must contain the actual data.

I changed the process. Now, the export reads each photo and converts it to a Base64 string inside the JSON.

This approach has trade-offs: • The file size grows by about 33 percent. • Large libraries require more memory during export.

I chose correctness over file size. A large backup is useful. A tiny backup that loses all images is worthless.

I also changed how I handle imports to ensure speed and safety:

  1. Write all photos to the new device disk first. This happens outside the database transaction to keep it fast.
  2. Run a single database transaction to link the new local paths to the entries.

I also built the system to fail soft. If one photo is missing or unreadable, the app skips it and moves to the next. One broken image should not crash a whole restore.

Lessons learned:

  • Test the right way. Export on one device, wipe it, and import on a clean install. Re-importing on the same device hides bugs.
  • Carry the bytes. If data must survive a device change, move the actual data, not the address.

Source: https://dev.to/diven_rastdus_c5af27d68f3/my-offline-apps-backup-lost-every-photo-on-a-new-phone-3d36