GithubHelp home page GithubHelp logo

sromku / adb-export Goto Github PK

View Code? Open in Web Editor NEW
103.0 103.0 17.0 21 KB

Bash script to export android content providers data to csv

License: Apache License 2.0

Shell 100.00%
adb android content-provider csv

adb-export's People

Contributors

sromku avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adb-export's Issues

THANK YOU. (no bug) - Here is a (much shorter) perl version

This perl script is much shorter and
• generates correct CSV
• Allows short names: adb-export.pl -e contacts
• Gathers exports in a single exports folder

#!/usr/bin/perl

use 5.14.2;
use warnings;

# Based on adb-export.sh from github.com:sromku/adb-export
# author: Roman Kushnarenko @sromku
# license: Apache License 2.0

our $VERSION = "0.01 - 20190718";
our $CMD = $0 =~ s{.*/}{}r;

sub usage {
    my $err = shift and select STDERR;
    say "usage: $CMD [--debug=[#]] --export[=URL]";
    say " URL list available on github: https://github.com/snatik/adb-export";
    exit $err;
    } # usage

use Text::CSV_XS qw( csv );
use Getopt::Long qw(:config bundling);
GetOptions (
    "help|?"            => sub { usage (0); },
    "V|version"         => sub { say "$CMD [$VERSION]"; exit 0; },

    "e|export:s"        => \ my @exp,

    "d|debug:1"         => \(my $opt_d = 0),
    "v|verbose:1"       => \(my $opt_v = 1),
    ) or usage (1);

my @d = localtime;
my $stamp = sprintf "%4d%02d%02d-%02d%02d", $d[5] + 1900, $d[4] + 1, @d[3,2,1];

my %all = (
    aggregation_exceptions      => "com.android.contacts/aggregation_exceptions",
    attendees                   => "com.android.calendar/attendees",
    audio_albums                => "media/external/audio/albums",
    audio_artists               => "media/external/audio/artists",
    audio_genres                => "media/external/audio/genres",
    audio_media                 => "media/external/audio/media",
    audio_playlists             => "media/external/audio/playlists",
    bookmarks                   => "settings/bookmarks",
    calendars                   => "com.android.calendar/calendars",
    contacts                    => "com.android.contacts/contacts",
    data                        => "com.android.contacts/data",
    data_phones                 => "com.android.contacts/data/phones",
    deleted_contacts            => "com.android.contacts/deleted_contacts",
    directories                 => "com.android.contacts/directories",
    events                      => "com.android.calendar/events",
    extendedproperties          => "com.android.calendar/extendedproperties",
    global                      => "settings/global",
    groups                      => "com.android.contacts/groups",
    images_media                => "media/external/images/media",
    images_thumbnails           => "media/external/images/thumbnails",
    photo_dimensions            => "com.android.contacts/photo_dimensions",
    raw_contact_entities        => "com.android.contacts/raw_contact_entities",
    raw_contacts                => "com.android.contacts/raw_contacts",
    reminders                   => "com.android.calendar/reminders",
    secure                      => "settings/secure",
    status_updates              => "com.android.contacts/status_updates",
    system                      => "settings/system",
    video_media                 => "media/external/video/media",
    video_thumbnails            => "media/external/video/thumbnails",
    words                       => "user_dictionary/words",
    );
my %lla = reverse %all;

-d "export" or mkdir "export", 0775;
@exp or @exp = sort values %all;
foreach my $url (@exp) {
    exists $all{$url} and $url = $all{$url};

    $url =~ s{^\w+://}{};

    my $base = $lla{$url} or die "Unsupported URL: '$url'\n";
    $base = "export/$base-$stamp";

    my $rawf = "$base.raw";
    $opt_v and warn sprintf "Exporting %-45s to %s\n", $url, $rawf;

    my $data = `adb shell content query --uri content://$url`;
    open my $fh, ">", $rawf;
    print   $fh $data;
    close   $fh;

    my $csvf = "$base.csv";
    $opt_v and warn sprintf "Exporting %-30s to %s\n", $url, $csvf;
    $data =~ m/^Row:\s*\d/ or next;
    my @h;
    my @r;
    for (split m/(?:^|\n)(?=Row:\s*\d+\s+\w+=)/ => $data) {
        s/^Row:\s*\d+\s+/, /;
        my @v = m/,\s+(\w+)=(.*?)(?=$|, \w+=)/g;
        unless (@h) {
            @h = map { $v[$_] } grep { $_ % 2 == 0 } 0 .. $#v;
            }
        my %v = @v;
        s/^NULL$// for values %v;
        push @r, \%v;
        }
    csv (in => \@r, out => $csvf, headers => \@h);
    $opt_v > 1 and warn sprintf "%17d records\n", scalar @r;
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.