Get app data on android device without root through adb backup

We find that the data on one of our app has problem, but we save the data on the app’s internal storage, that is /data/data folder, if the…

Get app data on android device without root through adb backup

We find that the data on one of our app has problem, but we save the data on the app’s internal storage, that is /data/data folder, if the device didn’t root, we can’t get the data from /data/data folder, I am thinking how to get data from android device without root the device.

Backup data with adb backup

After search the internet, and I get the answer to backup the data with adb backup command from How to access data/data folder in Android device?.

The backup command is:adb backup -noapk com.your.packagename

The are some details about backup and unpack the backup files on the page Unpacking Android backups.

Unpack the ab file

After we execute the backup command, the default backup file is named backup.ab , but how to get the data from the ab file?

Unpack with openssl zlib

On the page Unpacking Android backups, it mentioned the unpack command is like below:dd if=backup.ab bs=24 skip=1|openssl zlib -d > backup.tar

Unpack on mac with python

But on mac when we execute the command above, it will report the following error:openssl:Error: 'zlib' is an invalid command.Standard commands
asn1parse         ca                certhash          ciphers          
crl               crl2pkcs7         dgst              dh                
dhparam           dsa               dsaparam          ec                
ecparam           enc               errstr            gendh            
gendsa            genpkey           genrsa            nseq              
ocsp              passwd            pkcs12            pkcs7            
pkcs8             pkey              pkeyparam         pkeyutl          
prime             rand              req               rsa              
rsautl            s_client          s_server          s_time            
sess_id           smime             speed             spkac            
ts                verify            version           x509Message Digest commands (see the `dgst' command for more details)
gost-mac          md4               md5               md_gost94        
ripemd160         sha1              sha224            sha256            
sha384            sha512            streebog256       streebog512      
whirlpoolCipher commands (see the `enc' command for more details)
aes-128-cbc       aes-128-ecb       aes-192-cbc       aes-192-ecb      
aes-256-cbc       aes-256-ecb       base64            bf                
bf-cbc            bf-cfb            bf-ecb            bf-ofb            
camellia-128-cbc  camellia-128-ecb  camellia-192-cbc  camellia-192-ecb  
camellia-256-cbc  camellia-256-ecb  cast              cast-cbc          
cast5-cbc         cast5-cfb         cast5-ecb         cast5-ofb        
chacha            des               des-cbc           des-cfb          
des-ecb           des-ede           des-ede-cbc       des-ede-cfb      
des-ede-ofb       des-ede3          des-ede3-cbc      des-ede3-cfb      
des-ede3-ofb      des-ofb           des3              desx              
rc2               rc2-40-cbc        rc2-64-cbc        rc2-cbc          
rc2-cfb           rc2-ecb           rc2-ofb           rc4              
rc4-40

I also get the help from network, the link is Error: ‘zlib’ is an invalid command, and on mac, we can use the following commands:dd if=backup.ab bs=1 skip=24 | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" | tar -xvf -# Export to a tar file
dd if=backup.ab bs=1 skip=24 | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" > backup.tar

Backup Podcasts In practice

I will use Google Podcasts app as an example to demonstrate how to get the data for Podcasts.

I connect my android device with adb via wifi, the android serial is like below:

List devices$ adb devices -l
List of devices attached
adb-816d824e-2lp6Pe._adb-tls-connect._tcp. device product:curtana_eea model:Redmi_Note_9S device:curtana transport_id:11
emulator-5554          device product:sdk_gphone64_x86_64 model:sdk_gphone64_x86_64 device:emulator64_x86_64_arm64 transport_id:10

Get package for Podcasts# Connect device with adb shell
adb -s adb-816d824e-2lp6Pe._adb-tls-connect._tcp. shell# List package to get package name of Spotify
pm list packagesThe output is something like below, so I get the package for Podcasts is com.google.android.apps.podcasts...
package:com.google.android.apps.podcasts
...

Backup Podcasts dataadb -s adb-816d824e-2lp6Pe._adb-tls-connect._tcp. backup -noapk -f podcasts.ab com.google.android.apps.podcasts

Unpack backup file on macdd if=podcasts.ab bs=1 skip=24 | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" | tar -xvf -

After unpack the backup file, the files for the Podcasts are like below:tree -L 3
.
└── apps
   └── com.google.android.apps.podcasts
       ├── _manifest
       ├── d_f
       ├── db
       ├── f
       └── sp

How to prevent adb backup

When I tried for some apps, such as Spotify, and I can’t get the backup for the app, so I also searched how to prevent backup the app data with adb backup .

Setup android:allowBackup="false" on application setting on AndroidManifest.xml file.<application android:allowTaskReparenting=["true" | "false"]
            android:allowBackup=["true" | "false"]
            android:allowClearUserData=["true" | "false"]
            android:allowNativeHeapPointerTagging=["true" | "false"]
            android:backupAgent="string"
            android:backupInForeground=["true" | "false"]
            android:banner="drawable resource"
            android:dataExtractionRules="string resource"
            android:debuggable=["true" | "false"]
            android:description="string resource"
            android:enabled=["true" | "false"]
            android:extractNativeLibs=["true" | "false"]
            android:fullBackupContent="string"
            android:fullBackupOnly=["true" | "false"]
            android:gwpAsanMode=["always" | "never"]
            android:hasCode=["true" | "false"]
            android:hasFragileUserData=["true" | "false"]
            android:hardwareAccelerated=["true" | "false"]
            android:icon="drawable resource"
            android:isGame=["true" | "false"]
            android:killAfterRestore=["true" | "false"]
            android:largeHeap=["true" | "false"]
            android:label="string resource"
            android:logo="drawable resource"
            android:manageSpaceActivity="string"
            android:name="string"
            android:networkSecurityConfig="xml resource"
            android:permission="string"
            android:persistent=["true" | "false"]
            android:process="string"
            android:restoreAnyVersion=["true" | "false"]
            android:requestLegacyExternalStorage=["true" | "false"]
            android:requiredAccountType="string"
            android:resizeableActivity=["true" | "false"]
            android:restrictedAccountType="string"
            android:supportsRtl=["true" | "false"]
            android:taskAffinity="string"
            android:testOnly=["true" | "false"]
            android:theme="resource or theme"
            android:uiOptions=["none" | "splitActionBarWhenNarrow"]
            android:usesCleartextTraffic=["true" | "false"]
            android:vmSafeMode=["true" | "false"] >
   . . .
</application>

Another issue is that adb backup and adb restore is deprecated, and they might be removed in the future release.