Created
December 8, 2017 23:58
-
-
Save tyhicks/0d23aa4d01bacb2e18e7f6a5a628d157 to your computer and use it in GitHub Desktop.
Compare file sizes of snaps and xdelta3 diffs with and without mksquashfs' -no-fragments option
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/bash | |
set -e | |
resquash_snap() | |
{ | |
orig_snap="$1" | |
new_snap="$(basename "$orig_snap" .snap)-nofrag.snap" | |
tmp=$(mktemp -d resquash.XXXXXXXXXX) | |
dir="${tmp}/unsquashed" | |
unsquashfs -d "$dir" "$orig_snap" > /dev/null | |
fstime=$(unsquashfs -fstime "$orig_snap") | |
mksquashfs "$dir" "$new_snap" -noappend -comp xz -all-root -no-xattrs -no-fragments -fstime "$fstime" > /dev/null | |
rm -rf "$tmp" | |
printf "%s" "$new_snap" | |
} | |
generate_delta() | |
{ | |
orig="$1" | |
new="$2" | |
out="$(basename "$orig" .snap)-to-$(basename "$new" .snap).xdelta3" | |
xdelta3 -s "$orig" "$new" "$out" | |
printf "%s" "$out" | |
} | |
if [ "$#" -lt 2 ]; then | |
echo "Usage: $0 <OLDEST_SNAP> <NEWER_SNAP> [NEWER_SNAP] ..." 1>&2 | |
exit 1 | |
fi | |
prev= | |
prev_resquash= | |
for cur in "$@"; do | |
echo "### Resquashing $cur with no fragments" | |
cur_resquash=$(resquash_snap "$(basename "$cur")") | |
if [ -n "$prev" ]; then | |
delta=$(generate_delta "$prev" "$cur") | |
delta_resquash=$(generate_delta "$prev_resquash" "$cur_resquash") | |
du -h "$cur" "$cur_resquash" "$delta" "$delta_resquash" | |
else | |
du -h "$cur" "$cur_resquash" | |
fi | |
prev="$cur" | |
prev_resquash="$cur_resquash" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment