5,599,977 Members 45,882 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
jeffsf
Old
(Last edited by jeffsf; 9th February 2014 at 03:37 AM.) Reason: Add on-phone shell scripts
#1  
jeffsf's Avatar
Recognized Contributor - OP
Thanks Meter 960
Posts: 1,077
Join Date: Mar 2011
Location: San Francisco

 
DONATE TO ME
Default [TOOL] Fix TWRP Backup Dates / Find Your Phone's Birthday

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, 125 views)
File Type: txt spew-twrp-rename.sh.txt - [Click for QR Code] (1.2 KB, 40 views)
Nexus 5, custom OmniROM builds (don't panic, it means I can brick my SGS4G without fear)
Samsung Galaxy S 4G -- Development version of OmniROM
Fromerly: Development version of Team Acid's CM9 source, Hefe Kernel of Darkness, KG4 modem.
Working on: Cleaning up the build tree for OmniROM and Samsung kernel sources


WiFi Performance, GB vs. ICS, and how to measure it yourself.

FreeBSD, Ubuntu, MacOS X, OpenWRT
Motorola Micro-TAC ("Micro" ) Nokia 2160, 8260, 6681, E70, N900, then had to move on
The Following 10 Users Say Thank You to jeffsf For This Useful Post: [ Click to Expand ]
 
aquavalanche
Old
#2  
aquavalanche's Avatar
Senior Member
Thanks Meter 17
Posts: 167
Join Date: Jan 2012
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
Galaxy Nexus Maguro 16GB
LGE Nexus 5 Hammerhead 32GB
Galaxy S3 16GB International
Nexus 7 32GB
 
jonata
Old
#3  
jonata's Avatar
Senior Member
Thanks Meter 107
Posts: 1,988
Join Date: Jul 2007
good work bro.
Possible a zip file to flash for this ?
tks

HTCE ONE M8
Android Revolution HD 3.4
Moto X 16 GB
 
jeffsf
Old
#4  
jeffsf's Avatar
Recognized Contributor - OP
Thanks Meter 960
Posts: 1,077
Join Date: Mar 2011
Location: San Francisco

 
DONATE TO ME
Quote:
Originally Posted by jonata View Post
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.
Nexus 5, custom OmniROM builds (don't panic, it means I can brick my SGS4G without fear)
Samsung Galaxy S 4G -- Development version of OmniROM
Fromerly: Development version of Team Acid's CM9 source, Hefe Kernel of Darkness, KG4 modem.
Working on: Cleaning up the build tree for OmniROM and Samsung kernel sources


WiFi Performance, GB vs. ICS, and how to measure it yourself.

FreeBSD, Ubuntu, MacOS X, OpenWRT
Motorola Micro-TAC ("Micro" ) Nokia 2160, 8260, 6681, E70, N900, then had to move on
The Following User Says Thank You to jeffsf For This Useful Post: [ Click to Expand ]
 
dave2metz
Old
#5  
dave2metz's Avatar
Senior Member
Thanks Meter 165
Posts: 1,066
Join Date: Oct 2010
Location: Clearwater, Florida
Umm,, huh?

NEXUS 5
ADDICTED TO XDA SINCE 2010

- NEXUS 5 -
 
jeffsf
Old
(Last edited by jeffsf; 9th February 2014 at 03:19 AM.)
#6  
jeffsf's Avatar
Recognized Contributor - OP
Thanks Meter 960
Posts: 1,077
Join Date: Mar 2011
Location: San Francisco

 
DONATE TO ME
Quote:
Originally Posted by dave2metz View Post
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
Nexus 5, custom OmniROM builds (don't panic, it means I can brick my SGS4G without fear)
Samsung Galaxy S 4G -- Development version of OmniROM
Fromerly: Development version of Team Acid's CM9 source, Hefe Kernel of Darkness, KG4 modem.
Working on: Cleaning up the build tree for OmniROM and Samsung kernel sources


WiFi Performance, GB vs. ICS, and how to measure it yourself.

FreeBSD, Ubuntu, MacOS X, OpenWRT
Motorola Micro-TAC ("Micro" ) Nokia 2160, 8260, 6681, E70, N900, then had to move on
 
ldubs
Old
#7  
ldubs's Avatar
Senior Member
Thanks Meter 20
Posts: 297
Join Date: Dec 2012
Location: Brooklyn, NY
So open in terminal on phone and run ?

sent from my hammerhead


Insert witty, pithy, androidy statement here
 
jeffsf
Old
#8  
jeffsf's Avatar
Recognized Contributor - OP
Thanks Meter 960
Posts: 1,077
Join Date: Mar 2011
Location: San Francisco

 
DONATE TO ME
Yes, or over "adb shell" which makes cut-and-paste a lot easier.

Posted from whatever phone booted today.
Nexus 5, custom OmniROM builds (don't panic, it means I can brick my SGS4G without fear)
Samsung Galaxy S 4G -- Development version of OmniROM
Fromerly: Development version of Team Acid's CM9 source, Hefe Kernel of Darkness, KG4 modem.
Working on: Cleaning up the build tree for OmniROM and Samsung kernel sources


WiFi Performance, GB vs. ICS, and how to measure it yourself.

FreeBSD, Ubuntu, MacOS X, OpenWRT
Motorola Micro-TAC ("Micro" ) Nokia 2160, 8260, 6681, E70, N900, then had to move on
The Following 2 Users Say Thank You to jeffsf For This Useful Post: [ Click to Expand ]
 
howard bamber
Old
#9  
howard bamber's Avatar
Senior Member
Thanks Meter 152
Posts: 1,086
Join Date: Jun 2012
Location: Southport
Mine has it on the box!

Sent by mobile telephone.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


TRENDING IN THEMER...