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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
v0.2.0
changelog:unzip
is quiet