Set Up Your MediaTek Device with Comprehensive Beginner’s Guide

As can be seen with the use of MediaTek chips in Android One devices … more

Sony Updates AOSP Sources to Android 5.0.1

Just a few days ago, Sony did an utterly fantastic job by pushing out numerous device trees for … more

Stop Your Screen From Turning Off with KeepItOn

We all know the feeling of reading a news article orrather longdocument, when our screen … more

The XDA LG QPair Developer Challenge Voting Has Begun!

It seems like it was just yesterday that weannounced that we had paired up with LGto … more

Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[TOOL] Fix TWRP Backup Dates / Find Your Phone's Birthday

OP jeffsf

8th February 2014, 02:55 AM   |  #1  
jeffsf's Avatar
OP Recognized Contributor
Flag San Francisco
Thanks Meter: 980
 
1,086 posts
Join Date:Joined: Mar 2011
Donate to Me
More
Well, a week into my Nexus 5 and the dates on backups got to me. "Was that the one before or after I pooched my phone?"

I was doing rough conversions at first, then convinced myself that there was a reasonably fixed offset between "real time" and what TWRP was labeling things. @helicopter88 let me know that there was a missing ability in the chip, so I looked for a run-time solution. Unfortunately, adjtimex wouldn't take a large enough offset.

Since the reasonably useless date stamps on backups were, well, reasonably useless, I did write a little script that converted the dates on the backups to something that matched my local time, given the offset.

Looks like @Dees_Troy has saved me a bunch of coding inside TWRP as there is a going-forward fix in the TWRP sources now. Since he found the magic file where the offset is stored, you don't have to try to "guess" it from looking at your clock and your phone's (though $ date && adb shell date will get you the information you need).

For those backups you already have, here's how you can get the dates and times fixed up on them.

Edit -- Shell scripts made up for on-phone use:

sh birthday.sh while on the phone will give you offset and your phone's birthday (Yes, Korean time, of course!)

Code:
root@hammerhead:/ # sh /data/media/0/twrp-dates-tool/birthday.sh                                       <
1386550085
Mon Dec  9 09:48:05 KST 2013
sh spew-twrp-rename.sh /path/to/TWRP/BACKUPS will write the commands to move the directories to the terminal (stdout)

The "spew" script finds the offset itself.
It will rewrite both old (20th century) dates and current ones, but only time-shift the older ones.
It will also convert spaces in the file names to underscore characters.

See attached files (.txt added to allow upload)

No, there isn't a "zip" for this -- checking that the right things are being done with your backups before they can't be undone is important





Read on only if you want to do this using perl.


Now, you can adb pull /data/system/time/ to get two files, ats_1 and ats_2 that have the offset in milliseconds as a 64-bit unsigned integer. Pick one or the other, get the human-readable output trim off the last three digits, and there is your offset (within a second). Mine drifts a second each week or so, but hey, this is a lot closer than 1970 something!

Once you have the offset, this script will take a list of files and spit out the commands to rename them, if they match a TWRP-format date in the 1970s. (Edit $offset to match yours.)

Code:
#!/usr/bin/perl

use strict;

use Date::Parse;
use Date::Format;

my $offset = 1386550084; # Edit this to match your offset

my $line;
my ($year,$mo,$day,$h,$m,$s);

my $twrp_time;
my $new_time_string;
my $before;
my $after;

LINE:
while ( defined ( $line = <> ) ) {

    chomp $line; chomp $line;

    next LINE unless $line =~ m/((197\d)-(\d\d)-(\d\d)--(\d\d)-(\d\d)-(\d\d))/;

    $before = $`; $after = $';
    $twrp_time = str2time("$2/$3/$4 $5:$6:$7 GMT");

    $new_time_string = time2str("%Y-%m-%d_%H%M%S%z", $twrp_time + $offset);

    $before =~ s/ /_/g;
    $after =~ s/ /_/g;

    print "mv '$line' ${before}${new_time_string}${after}\n";
}


Output looks like
Code:
mv '1970-02-22--23-02-13 omni_hammerhead-userdebug 4.4.2 KOT49H 128' 2014-01-30_155017-0800_omni_hammerhead-userdebug_4.4.2_KOT49H_128
mv '1970-02-23--13-50-29 omni_hammerhead-userdebug 4.4.2 KOT49H 128' 2014-01-31_063833-0800_omni_hammerhead-userdebug_4.4.2_KOT49H_128
mv '1970-02-23--15-22-06 omni_hammerhead-userdebug 4.4.2 KOT49H 126' 2014-01-31_081010-0800_omni_hammerhead-userdebug_4.4.2_KOT49H_126
mv '1970-02-23--16-10-01 omni_hammerhead-userdebug 4.4.2 KOT49H 126' 2014-01-31_085805-0800_omni_hammerhead-userdebug_4.4.2_KOT49H_126
mv '1970-02-25--17-11-08 omni_hammerhead-userdebug 4.4.2 KOT49H 127' 2014-02-02_095912-0800_omni_hammerhead-userdebug_4.4.2_KOT49H_127
which you can copy and paste into a shell on your device, or other places you have your TWRP backups backed up.

.
Attached Files
File Type: txt birthday.sh.txt - [Click for QR Code] (436 Bytes, 154 views)
File Type: txt spew-twrp-rename.sh.txt - [Click for QR Code] (1.2 KB, 43 views)
Last edited by jeffsf; 9th February 2014 at 04:37 AM. Reason: Add on-phone shell scripts
The Following 10 Users Say Thank You to jeffsf For This Useful Post: [ View ]
8th February 2014, 03:28 AM   |  #2  
aquavalanche's Avatar
Senior Member
Thanks Meter: 19
 
177 posts
Join Date:Joined: Jan 2012
More
Whoa! Nice one man! A bit of extra work is just fine rather than renaming each of the backups! Thanks a bunch

Sent from my Nexus 5 using Tapatalk
8th February 2014, 07:45 PM   |  #3  
jonata's Avatar
Senior Member
Flag Casette d'Ete
Thanks Meter: 111
 
2,032 posts
Join Date:Joined: Jul 2007
More
good work bro.
Possible a zip file to flash for this ?
tks
8th February 2014, 08:33 PM   |  #4  
jeffsf's Avatar
OP Recognized Contributor
Flag San Francisco
Thanks Meter: 980
 
1,086 posts
Join Date:Joined: Mar 2011
Donate to Me
More
Quote:
Originally Posted by jonata

Possible a zip file to flash for this ?

Let me look into what options there are in toolbox/busybox for the date parsing. As this was a quick-and-dirty solution, I didn't dive into trying to get it to run on the device.
The Following User Says Thank You to jeffsf For This Useful Post: [ View ]
8th February 2014, 11:16 PM   |  #5  
dave2metz's Avatar
Senior Member
Flag Clearwater, Florida
Thanks Meter: 191
 
1,206 posts
Join Date:Joined: Oct 2010
More
Umm,, huh?

NEXUS 5
9th February 2014, 12:59 AM   |  #6  
jeffsf's Avatar
OP Recognized Contributor
Flag San Francisco
Thanks Meter: 980
 
1,086 posts
Join Date:Joined: Mar 2011
Donate to Me
More
Quote:
Originally Posted by dave2metz

Umm,, huh?

To be clear, the perl scripts run on something that has perl installed, like your laptop or desktop. The output runs just fine over adb shell to rename files on your phone. It also works just fine to rename the backup copies that you are keeping on your Mac, Linux, FreeBSD box. For Windows without Cygwin or similar, you'd want to change "mv" to "move"

Edit -- shell scripts for on-phone use added to lead post
Last edited by jeffsf; 9th February 2014 at 04:19 AM.
10th February 2014, 04:43 AM   |  #7  
ldubs's Avatar
Senior Member
Brooklyn, NY
Thanks Meter: 29
 
408 posts
Join Date:Joined: Dec 2012
More
So open in terminal on phone and run ?

sent from my hammerhead
10th February 2014, 07:23 PM   |  #8  
jeffsf's Avatar
OP Recognized Contributor
Flag San Francisco
Thanks Meter: 980
 
1,086 posts
Join Date:Joined: Mar 2011
Donate to Me
More
Yes, or over "adb shell" which makes cut-and-paste a lot easier.

Posted from whatever phone booted today.
The Following 2 Users Say Thank You to jeffsf For This Useful Post: [ View ]
13th March 2014, 05:36 PM   |  #9  
howard bamber's Avatar
Senior Member
Southport
Thanks Meter: 184
 
1,317 posts
Join Date:Joined: Jun 2012
Mine has it on the box!

Sent by mobile telephone.

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes