Automating nested ZIP extraction on Synology NAS

Hey folks! I’m in a bit of a pickle with my Synology NAS. Got this huge Notion backup file that’s basically a zip within a zip. I want to set up a script to unpack it all without me having to babysit the process. The tricky part is that the regular unzip tool isn’t an option on my NAS.

I’ve noticed 7z is installed, but I’m scratching my head on how to make it handle these nested archives smoothly. Any ideas on how to whip up a Bash script that can dig through and extract all the zipped files inside automatically? I’m not exactly a command-line wizard, so simple explanations would be super helpful. Thanks in advance for any tips!

I’ve tackled a similar issue with nested ZIPs on my Synology NAS. Here’s a Bash script that might help:

#!/bin/bash
extract_nested() {
    for file in *.zip; do
        7z x "$file" -o"extracted_$file"
        cd "extracted_$file"
        if ls *.zip 1> /dev/null 2>&1; then
            extract_nested
        fi
        cd ..
    done
}

extract_nested

This script uses 7z to extract all ZIP files in the current directory, then recursively does the same for any ZIPs found inside. Save it as ‘extract_nested.sh’, make it executable with ‘chmod +x extract_nested.sh’, and run it in the directory with your Notion backup.

It’s not perfect - you might need to tweak it depending on your exact file structure. But it should give you a good starting point. Just be careful with large backups, as this could eat up disk space quickly!

yo, i’ve been there with those pesky nested zips. here’s a quick n dirty one-liner that might do the trick:

while find . -name ‘.zip’; do find . -name '.zip’ -exec 7z x ‘{}’ ; ; done

just paste that in ur terminal. it’ll keep diggin til it finds all the zips and extract em. might take a while tho, so grab a coffee n chill. good luck!

Having dealt with nested archives on Synology NAS myself, I can offer a slightly different approach. Instead of a recursive function, you might find it simpler to use a while loop. Here’s a script that could work:

#!/bin/bash
while find . -type f -name ‘.zip’ | grep -q .; do
find . -type f -name '
.zip’ -print0 | xargs -0 -I {} 7z x ‘{}’ -o’{}_extracted’
find . -type f -name ‘*.zip’ -delete
done

This script repeatedly searches for ZIP files, extracts them, and then deletes the originals. It continues until no more ZIP files are found. It’s straightforward and doesn’t require nested function calls. Remember to test this on a small subset of your data first, and ensure you have enough disk space, as extracting large backups can quickly fill up your NAS.