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 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