I'm having problems with my internal flash storage (namely not being able to create folders in root, which prevents some apps from working, plus periodic unmounts), and I have tried unsuccessfully to run fsck
on it, so I figured I would back up my data, format the internal flash storage, and restore. Running adb pull /storge/sdcard0
will, however, replace the files' modification date, which will be an issue with photos, for example, since the Gallery depends on those dates to sort pics. My question is if there is a way to preserve that data.
3 Answers
There are several ways you could accomplish that:
- if you have sufficient free storage available, archiving the contents (zip, tar, whatever other archiver) and then copying the archive file would be a way. Pulling the archive would change the archive file's timestamp, but contents would be preserved as-is, and restored with their original timestamps. This could be done either from a terminal app, or via
adb shell
. On one device I've checked,tar
andgzip
are available, and evenbzip2
. Successfully tested on another one, and adapted to your specifications:tar czf backup.tar.gz /storge/sdcard0
run from a location with sufficient space would create the archive, which you then could pull. - you could utilize a sync app like FolderSync, and simply sync all the contents to your computer (via SFTP, Samba/Windows-Share, or any of the other supported protocols). After having formatted the storage, you could sync it back the very same way.
- if your device supports an external SDCard, you could copy your files over there, which also should preserve timestamps
There might be even other possibilities, but these are the ones coming to my mind first.
Try using the -a
option to copy all file attributes:
adb pull -p -a /sdcard/
(The -p
is for progress indication.)
-
where to see list of available options such as
-a
-p
and so on Commented Jul 14, 2023 at 13:14 -
any suggestion on pushing backup back to
/sdcard/
on a new phone?– TJMCommented Dec 3, 2023 at 6:53
Over ssh, we can also use rsync with the -a
option:
rsync -a /sdcard/ <destination>
--delay-directory-restore
option.