Skip to content

Instantly share code, notes, and snippets.

@jficz
Last active June 6, 2021 01:47
Show Gist options
  • Save jficz/c515a4ead069b61f1231d68d361f882e to your computer and use it in GitHub Desktop.
Save jficz/c515a4ead069b61f1231d68d361f882e to your computer and use it in GitHub Desktop.
OandBackupX old (zip) -> new (tar.gz) backup converter
#!/bin/sh
# v0.2.0
# works for me, ymmv
BDIR=${1:-.}
_delete_cache=${DELETE_CACHE:-true}
_data=data
_ext=external_files
_prot=device_protected_files
_tmp=`mktemp -d`
_olddir=`pwd`
cd $BDIR
BDIR=`pwd`
_app=`basename $BDIR`
echo "Converting \`$_app\`..."
if [ -f $_app.zip ]; then
echo " Moving app data \`$_app.zip\` to \`data/\`."
mkdir $_data
mv $_app.zip $_data
echo
fi
for _dir in $_data $_ext $_prot; do
echo " Processing \`$_dir\`..."
cd $BDIR
if [ -f $_dir/$_app.zip ]; then
mkdir -p $_tmp/$_dir
echo " Unzipping \`$_dir/$_app.zip\` to tmp directory."
unzip $_dir/$_app.zip -d "$_tmp/$_dir" >/dev/null
cd $_tmp
echo " Fixing directory structure."
mv $_dir/$_app/* $_dir/
rmdir $_dir/$_app
[ "$_delete_cache" == "true" ] && (echo " Deleting cache."; rm -rf $_dir/*cache*)
[ "`ls $_dir/`" != "" ] && (echo " Creating \`$_dir.tar.gz\`."; tar czf $_dir.tar.gz $_dir)
cd $BDIR
if [ -e "$_tmp/$_dir.tar.gz" ]; then
echo " Moving \`$_dir.tar.gz\` to the app backup directory."
mv $_tmp/$_dir.tar.gz .
else
echo " \`$_dir\` is empty, ignoring."
fi
else
echo " Nothing to do."
fi
echo " Finished processing \`$_dir\`."
echo
done
echo " Cleaning up tmp files."
rm -rf $_tmp
echo "Backup \`$_app\` converted."
cd $_olddir
@jficz
Copy link
Author

jficz commented Sep 8, 2020

Doesn't create a compatible backup source if the old bakup's protected_device_data does not contain the actual data. Probably the same for external_data. Fixed in v0.2.0

@jficz
Copy link
Author

jficz commented Sep 8, 2020

Note that this script should be compatible with Android shell, too.

Deletes cache if present. This can be disabled by setting env DELETE_CACHE=false .

The script does not delete any of the old backup data but It does move one of the old files to a subdirectory, breaking compatibility. If you need to restore the compatibilty, do
mv data/* .; rmdir data
inside the backup directory.

@jficz
Copy link
Author

jficz commented Sep 9, 2020

v0.2.0 changelog:

  • empty archives don't end up in backup directory (this invalidated the backup)
  • basic log output, unzip is quiet

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