Can't create a backup
- [x] I have searched open and closed issues for duplicates
- [x] I am submitting a bug report for existing functionality that does not work as intended
- [x] I have read https://github.com/signalapp/Signal-Android/wiki/Submitting-useful-bug-reports
- [x] This isn't a feature request or a discussion topic
Bug description
I can't create a backup. The behavior is exactly the same as described in Bug #7763 , but as this one has been closed more than two years ago, I assume it's another bug. After switching the backup switch on, I get the security number. When I try to create a backup, the messages counter counts, up to about 18,000 in my case, but when it's finished, no backup is there. "Last backup: Never". /Signal/Backups/ is created, but it's empty. No error message. Retrying it yields the same result. Switching backups off an on again shows another security number, but still, no backup is created. This happens no matter if the SD card is mounted or not (which was mentionned as a possible workaround in #7763).
Device: Samsung Galaxy A9 Android version: 8.0.0 Signal version: 4.70.5
Link to debug log
https://debuglogs.org/7881d64ea90bc285c0427b915df88d8d402626fd8d62ca5581642c4ae31e3d10
Interesting part may be esp. e. g. "09-09 23:18:45.636 12386 12433 W LocalBackupJob: Failed to rename temp file"
Interesting part may be esp. e. g. "09-09 23:18:45.636 12386 12433 W LocalBackupJob: Failed to rename temp file"
I've seen that a few times, too. I think (?) it usually went away when I cleared even more space for the backup. Maybe moving the backup requires twice the space because it crosses file system boundaries?
Is this actually the case?! At least, Signal should check this and warn about it, or some error message should pop up if it fails.
Having an old phone with limited internal storage then actually renders doing a backup impossible if it runs out of space, as the backup can't be placed on SD storage (which really, really should be changed, as already requested in Bug #7521, or PR #9015) … this is really a severe problem …
The rename documentation says:
* <p>Many failures are possible. Some of the more likely failures include:
* <ul>
* <li>Write permission is required on the directories containing both the source and
* destination paths.
* <li>Search permission is required for all parents of both paths.
* <li>Both paths be on the same mount point. On Android, applications are most likely to hit
* this restriction when attempting to copy between internal storage and an SD card.
* </ul>
If that gives you any clues to your situation that will help us address further.
This said first: It's my wife's phone. She neither changed anything concerning Signal or it's permissions, nor did she ever do anything odd (rooting, playing around with settings or whatever). Just did a default installation of Signal back then.
Signal has write permissions set, as by default. I can copy files into Internal/Signal/Backups/, rename them and delete them. As the backup apparently (and sadly! It really should, along with all chat data …) can't be placed in the SD card (where, per settings, Signal could also write to), I think the third point doesn't apply here?
The storage left should be sufficient, Android reports it to be 2.5 GB whereas Signal says it used 1.7 GB for the chat data. Also, as said, I got no error message or warning about insufficient space.
Has it ever had a successful backup on that device?
This was the first try.
Could it be that on some platforms, getExternalStorageDirectory() and getExternalCacheDir() (from StorageUtil.java) returns directories on different mount points, causing renameTo() to fail?
Fyi, getExternalStorageDirectory() is deprecated on API 29:
To improve user privacy, direct access to shared/external storage devices is deprecated. When an app targets Build.VERSION_CODES.Q, the path returned from this method is no longer directly accessible to apps. Apps can continue to access content stored on shared/external storage by migrating to alternatives such as Context#getExternalFilesDir(String), MediaStore, or Intent#ACTION_OPEN_DOCUMENT.
Is there a way I can check this on this very device? Alas, I never coded Java/Android (yet, but I know e. g. C++/Qt a bit). I would really like to help to track this down, as this is quite a problem here.
During backup it first writes a temporary file in private which it then renames. That rename is failing. So we're going to try creating that temporary file directly in the backup location.
That would definitely rule out the renaming to fail because of different mount points. Just to say this again: Everybody with interal storage running out would greatly appreciate if the backup target could be configured, so that it could be created on SD – and it seems to me that creating the backup in-place is crucial for being able to do so.
Just fyi: I tried quite hard to get more space by deleting all kind of stuff from the internal memory. Also, I deleted quite some big images and videos from Signal's media, so that the backup size would decrease. Finally, I actually could create a backup. So maybe, the backup process does, at least temporarily, need much more space than the final backup takes.
I deleted Signal, reinstalled it and restored the backup (which was about 1.7 GB). Afterwards, the space used by Signal dropped from about 4 GB before to 1.8 GB. This is another issue, but apparently, there was quite some spare, undeletable space occupied by Signal …
@alan-signal I can confirm that your free space seemingly needs to be more than double the backup size in order for backups to succeed. My Signal backups were reported as 3.30 GB and my phone was showing it had 6.90 GB free. Even though that should have been enough for two backups with 0.30 GB left, Signal backups would fail. I did some cleanup on my phone and got the free space to slightly above 7 GB (I don't remember the exact amount, maybe around 7.2 GB) and now the backup works fine.
@greyson-signal The issue here is that the UI reports the backup as complete before renameTo() has returned. On Android 11 when rename would fail it instead calls File.move, this seems to happen every time.
The bug is that the UI reports complete before the File.move operation has completed (or i guess this is really an upstream bug, but not one that's likely to be changed).
NVM it's fixed in the pr above, derp.