Skip to content

Instantly share code, notes, and snippets.

@samba
Created November 28, 2012 07:14
Show Gist options
  • Save samba/4159581 to your computer and use it in GitHub Desktop.
Save samba/4159581 to your computer and use it in GitHub Desktop.
Compressed disc image restoration with "threading"
#!/bin/sh
# Assumes images are broken out into 1024mb chunks, separately gzipped,
# stored as ./image/image.X.blob.gz, where X is an integer (0...).
# Decompresses and writes 6 in parallel (i.e. threading) since Gzip is slow.
DEVICE=$1
sectionsize=1024
maxthreads=5
curthreads=0
set -x
for i in `seq 0 2786`; do
blockcount=$(( sectionsize * i ))
zcat image/image.$i.blob.gz | dd of=$DEVICE bs=1M count=${sectionsize} seek=${blockcount} iflag=fullblock &
if [ $maxthreads -eq $curthreads ]; then
curthreads=0
wait
else
curthreads=$(( curthreads + 1 ))
fi
done
set +x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment