Last active
June 6, 2021 01:47
-
-
Save jficz/c515a4ead069b61f1231d68d361f882e to your computer and use it in GitHub Desktop.
OandBackupX old (zip) -> new (tar.gz) backup converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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.
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
Doesn't create a compatible backup source if the old bakup'sFixed inprotected_device_data
does not contain the actual data. Probably the same forexternal_data
.v0.2.0