Skip to content

Instantly share code, notes, and snippets.

@sandeep048
Created March 12, 2015 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandeep048/a2ad77012f8f8767fc04 to your computer and use it in GitHub Desktop.
Save sandeep048/a2ad77012f8f8767fc04 to your computer and use it in GitHub Desktop.
This simple script will backup user installed android applications to the computer. Extremely useful when there is not enough space in the phone. Requires working 'adb shell'.
#!/usr/bin/env python
import subprocess
adb_process = subprocess.Popen(
'adb shell pm list packages -f', shell=True, stdout=subprocess.PIPE)
user_packages = []
while True:
output_line = adb_process.stdout.readline().strip()
if len(output_line) == 0:
break
if 'data' in output_line:
user_packages.append(output_line)
for fpath, fname in [(x.split(':')[1].split('=')[0], x.split('=')[1] + '.apk') for x in user_packages]:
subprocess.Popen('adb pull %s %s' %
(fpath, fname), shell=True, stdout=subprocess.PIPE)
# adb_output, adb_error = process.communicate()
# print user_packages
# adb_output, adb_error = process.communicate()
@sandeep048
Copy link
Author

Learn how to use adb backup to save app data as well when the mobile is rooted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment