Skip to content

Instantly share code, notes, and snippets.

@raphiz
Created December 28, 2014 21:56
Show Gist options
  • Save raphiz/8c904f613a9778e4db9e to your computer and use it in GitHub Desktop.
Save raphiz/8c904f613a9778e4db9e to your computer and use it in GitHub Desktop.
Converts the contents of a .ab android backup file into a .tar archive
#!/usr/bin/env bash
#
# Converts the contents of a .ab android backup file into a .tar archive
#
# Usage: android-backup-extractor.sh SOURCE <DESTINATION>
#
# Requirements: dd, openssl
# License: MIT
# Autor: Raphael Zimmermann (http://raphael.li)
#
#
#
# Work is based on: http://nelenkov.blogspot.ch/2012/06/unpacking-android-backups.html
# Check if the first parameter is given...
if [ -z "${1+1}" ]; then
echo "Please specify a source file!";
exit 1
fi
# Assign the source file
SOURCE="$1"
# Verify the source file exists
if [ ! -f "$SOURCE" ]; then
echo "The given backup source $SOURCE is not a file!"
exit 1
fi
# If a second parameter is given, this shall be our destination
if [ -z "${2+1}" ]; then
DESTINATION="${SOURCE:0:-3}.tar"
else
DESTINATION="$2"
fi
# Verify the destination file does NOT exist
if [ -e "$DESTINATION" ]; then
echo "The destination file $DESTINATION does already exist!"
exit 1
fi
# From now on, prevent empty variables
set -u
# Notify user
echo "Extracting backup file $SOURCE to $DESTINATION"
# Start the extraction....
dd if="$SOURCE" bs=24 skip=1|openssl zlib -d > "$DESTINATION"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment