[GUIDE][HOW-TO]Keep timestamp and attributes correct

Search This thread

[email protected]

Senior Member
May 27, 2016
141
2
toronto
Has anyone found a solution using software-wise or by any other means to transfer a file (could be anything) to windows PC keeping/preserving date created, date modified, date accessed of that file/folder to the PC without any problems? Is this even possible? The emphasis is on *FILES & FOLDERS*
 

tag68

Senior Member
Nov 25, 2014
962
353
Moto G 2014
Moto X Play
To be sure to restore these states, you should use an archiver. Example
tar cvf filename.tar *
For archive
tar xvf filename.tar
For extracting.
If you have the rights, this should always work fine, and I think date and time of folder is being restored also. But I'm not sure if nanoseconds are being restored, or if tar only stores seconds.
 

[email protected]

Senior Member
May 27, 2016
141
2
toronto
To be sure to restore these states, you should use an archiver. Example
tar cvf filename.tar *
For archive
tar xvf filename.tar
For extracting.
If you have the rights, this should always work fine, and I think date and time of folder is being restored also. But I'm not sure if nanoseconds are being restored, or if tar only stores seconds.
This seems to be a linux workaround but Im using windows 10
 

tag68

Senior Member
Nov 25, 2014
962
353
Moto G 2014
Moto X Play
You may use tar on Android, Linux, Mac or Windows. As you like. The only difference is that Linux (and Mac) does deliver tar itself, for Android and Windows you may need a download.

If you don't like tar, you can try any other archiver that exists on all concerned OS, eg 7z or zip could be fine also.

The idea is that the archiver stores the date and restores it. This is a different, much more reliable approach than trying to copy timestamp. Especially for folders the file operations usually don't even try to restore the timestamp, the idea is that the folder is created when copying. Archivers mostly care about folder dates. Gnutar has quite some logic implemented to first copy all of the the files and afterwards set the timestamp for the folder, because adding a file to a folder sets a new timestamp.

This is the background why I recommended tar. It is the oldest tool, very reliable and exists nearly everywhere.
 

[email protected]

Senior Member
May 27, 2016
141
2
toronto
You may use tar on Android, Linux, Mac or Windows. As you like. The only difference is that Linux (and Mac) does deliver tar itself, for Android and Windows you may need a download.

If you don't like tar, you can try any other archiver that exists on all concerned OS, eg 7z or zip could be fine also.

The idea is that the archiver stores the date and restores it. This is a different, much more reliable approach than trying to copy timestamp. Especially for folders the file operations usually don't even try to restore the timestamp, the idea is that the folder is created when copying. Archivers mostly care about folder dates. Gnutar has quite some logic implemented to first copy all of the the files and afterwards set the timestamp for the folder, because adding a file to a folder sets a new timestamp.

This is the background why I recommended tar. It is the oldest tool, very reliable and exists nearly everywhere.
Is it native to windows 10 or is there a specific software that I need to download to use TAR ? What im trying to do is preserve all date and time fields of FOLDERS and FILES from android and transfer them to desktop PC for archiving and storage. So your saying TAR will allow this?
 

tag68

Senior Member
Nov 25, 2014
962
353
Moto G 2014
Moto X Play
It is said that tar is included with Windows 10:


tar does not transfer files. It is only an archiver. But you don't need to check if the transfer is being done timestamp-aware because you don't transfer the single files and folders, only an archive. If the archive does not keep timestamp when getting transferred, it does not harm. tar should be an easy helper for what you want to achieve.

On my Android device tar is directly available when called in a terminal.

If you want some GUI, so you don't need to use the command line, you will most probable need to download some archiver helper. Guess 7zip GUI will be fine for creating and extracting tar on Windows.
 

ThatGangsta39

Member
Nov 29, 2012
19
4
Has anyone found a solution using software-wise or by any other means to transfer a file (could be anything) to windows PC keeping/preserving date created, date modified, date accessed of that file/folder to the PC without any problems? Is this even possible? The emphasis is on *FILES & FOLDERS*

I've managed to copy my files with the tool "TotalCommander". It's a german file manager, similar to the Windows Explorer, but you can easily copy files over MTP and transfers the timestamps, if previously enabled in settings.
However, I noticed when copying the pictures to my new smartphone (Samsung), that it won't maintain these timestamps - unlike other smartphone brands, like LG or Xiaomi
 

[email protected]

Senior Member
May 27, 2016
141
2
toronto
I've managed to copy my files with the tool "TotalCommander". It's a german file manager, similar to the Windows Explorer, but you can easily copy files over MTP and transfers the timestamps, if previously enabled in settings.
However, I noticed when copying the pictures to my new smartphone (Samsung), that it won't maintain these timestamps - unlike other smartphone brands, like LG or Xiaomi
So your saying specific LG and Xiaomi phones do preserve the date created, date modified and date accessed of files and/or folders to PC or to another android device ? Which smartphone models like Xiaomi and LG preserves file and folder date and timestamps (without worrying about DST changes) ?

I've tested total commander and it only preserves the date modified, date created and date accessed doesn't get preserved. I know this and verified this after plugging my android phone to PC and using file explorer to see the video, photo or document such as pdf files etc..

I have not tried using TAR archives yet because if there is someone who can prove to me all 3 date and timestamps are preserved when copying or moving the archive to PC...then I would try it
 

Top Liked Posts

  • There are no posts matching your filters.
  • 25
    1. What is the problem?
    The implementation of FUSE by Google runs using the root-account. The disadvantage is that the standard user is not capable of changing any attribute including timestamp. A copy or move file operation usually keeps all attributes including date and time on all known operating system - except Android if FUSE is involved. This can complicate management of backups or syncing - and sorting or filtering by date is not helpful anymore.


    2. What is concerned?
    The problem exists at least on all file systems which are emulated by Android using FUSE. Android 8 and later uses SDCardFS and therefore is not concerned.

    Concerned from Android 4.0: ext4, exFAT
    Not Concerned on 4.0: FAT32
    It seems FAT32 is done via FUSE in later Android versions also, so it seems every file system is concerned from 4.1 to last Android 7.

    Most Android 4.x-devices are using ext4 for the file system of the internal storage and are therefore concerned. The usage of FAT32 which can not manage file greater than 4 GiB seems not appropriate anyway. For memory cards smaller than 64 GiB it is usual to use FAT32, bigger cards use exFAT by default.

    It is possible to access external file systems, eg SAMBA or FTP, and then usually the timestamp is set correctly, because this is not part of FUSE and uses other file systems. AFAIK most file manager still try to set the timestamps, although it always fails without root, and ignore the error returned by FUSE, so copying and moving should be fine. At least Total Commander copies the timestamp fine if writing to Samba using the appropriate plug-in on non-rooted devices.


    3. How to recognize/test the problem?
    If you copy or move a file, the date and time should be kept. But if the destination on Android uses FUSE, instead of the original timestamp the current date/time is being set. Also all other attributes which the file system may manage (rights, owner, groups etc.) usually are concerned. The original values vanish.

    If you want to see which file system is being used for internal memory or some external card you may use the app DiskInfo.
    If it shows vfat, it means FAT32.



    4. Which possibilities exist to correct the behavior?
    Google fixed the bug in Android 8 which was known for a long time (start of 2009).
    Google issue 34691 with links to related issues
    With Android 8 usage of FUSE was removed, the problem was corrected
    https://issuetracker.google.com/issues/36930892#comment120
    (careful when using command line under Android 8: cp -a seems not always to be working, but touch -r will)

    5. Which possibilities exist to circumvent the problem?

    5.0. do not use Android for writing to filesystem: If you don't use Android for writing the files, setting the timestamp mostly will be fine. As mentioned in 4. you can use any filesharing server (Samba, ftp etc.). Storing your documents there instead of the local device will relocate the write access to the filesystem of the filesharing server, which usually manages timestamps fine. There also exist possibilities like adopted storage mode, where the SD card gets accessed by Linux and Android only is being used like a card reader.

    As the files have the owner root, all possibilities to circumvent using Android need a rooted device. All following solutions shown here won't work for devices which are not rooted.

    5.1. Afterwards correcting (not tested): In the app store there exists at least one app File Timestamp which can afterwards set the timestamp.

    5.2. Samba Filesharing runs under root account. If some file is accessed via samba server, the time stamp and attributes can be set correctly.

    5.3. Make use of a file manager which sets the timestamp using the power of root on a rooted device:
    X-Plore sets file time after copying if root mode is enabled.
    Ghost Commander is said to work fine (additional requirement: Busybox)
    Total Commander 2.04 and newer support changing the time stamp under root account. On Android 5 and newer you need to use link /storage/xxxx-xxxx for external SD, not ///_Name, to make it behave correctly.
    SManager by devwom also deals fine with timestamp using root
    MiXplorer tries calling touch. The standard touch on some Android versions is faulty implemented, MiXplorer then only succeeds when BusyBox (internal download of MiX) is installed. Try if it works on your device with your current setup, and have a second look if the timezone correctly evaluated.

    5.4. Manual call via command line: Who opens a terminal (eg Open Android Terminal) on a rooted device preferrably with BusyBox can execute commands as root.

    Example 5.4.

    Archive (also possible on Unix/Windows/etc)

    cd <Quelle>
    tar -cf <Pfad_zu_Archiv>/Archiv.tar *


    Extract

    cd <Ziel>
    su
    tar -xf <Pfad_zu_Archiv>/Archiv.tar


    Copy

    su
    cp -a <Quelle> <Ziel>


    The command su changes to root user, so that write access to time stamps is possible. It is always possible to read them, so that it is not necessary to su before archive.

    Careful when calling touch: The standard implementation (toybox) seems to be faulty, it does not set the given time when called using -d or -t switch.
    Careful when using Android 8 (root not required), it seems at least some implementation of cp does not set timestamp on cp -a
    3
    I've reinstalled Busybox in /sbin as another guy asks me and I add "cp" and "mv" from Busybox. They keeps timestamps while while standard and toybox commands don't do it. It's a good thing for my scripts :) .

    And now I can see /sbin with TC.
    3
    Thanks OP, I have been searching Google for ways to copy photos to my phone while preserving timestamps and this thread is the only one that provided a usable solution.

    My experience with Samsung Galaxy S4 running stock Lollipop:
    Asus File Manager - Copy via SMB from Windows. Does not preserve timestamps.
    ES File Explorer - Copy via SMB from Windows. Does not preserve timestamps.
    Droid Explorer x64 (PC based, copy via USB/ADB) - Did not preserve timestamps, however, this was recommended in other threads.
    Total Commander - Copy via SMB from Windows. It works perfectly, files copied to External SD preserves timestamps.
    Ghost Commander - Copy via SMB from Windows. Enabled auto root and saw toast notifications it was granted root, but didn't copy to External SD at all. Acted like it was, but nothing was copied. Could not even delete from external SD, got a permission error. Lollipop has an annoying extra step of having to grant write access to External SD. Every other file manager was able to ask for it, Ghost Commander never did.
    X-Plore File Manager - Copy via SMB from Windows. SMB timeout on several files with only option to SKIP. Files copied to External SD did preserve timestamps, but being forced to skip files due to SMB timeout error makes it unusable (no RETRY button).

    For me, looks like Total Commander is the only workable solution so I've uninstalled everything else.
    2
    Does this affect F2FS as well?
    2
    Using ADB to perserve timestamp and attributes when copying

    I found the best way to copy files from my PC to an Andriod device and keep both time stamps and attributes correct, is to use TWRP Boot loader and ADB. (Might work with other bootloaders, but I only tested TWRP (v3.0.0) on Nexus 7.)

    If you have a bunch of file and folders you should be one directory up on the push.
    i.e. Files are in /top/backup on the PC.

    cd into /top

    Then:
    adb devices
    adb reboot recovery
    adb push backup/ /sdcard

    adb shell
    chgrp -R media_rw <FILES>
    chown -R media_rw <FILES>