Skip to content

Instantly share code, notes, and snippets.

@samba
Created August 27, 2012 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samba/3489640 to your computer and use it in GitHub Desktop.
Save samba/3489640 to your computer and use it in GitHub Desktop.
DD Imaging util
#!/bin/sh
# usage:
# sudo dd-local-monitor.sh if=/dev/sda bs=24M | gzip > /mnt/external/myimage.blob.gz
main () {
echo "# dd: $@" >&2
dd $@ &
DDPID=$!
while ps $DDPID >/dev/null; do
kill -USR1 $DDPID || break
sleep 10
done
}
main "$@"
#!/bin/sh
# arg 1: start index (default 0)
# arg 2: end index (default 20000)
REMOTE=root@remote-server
REMOTE_DEVICE=/dev/sda
OUTPUT=/mnt/external/images/0
mkdir -p $OUTPUT
sectionsize=1024
for i in `seq ${1:-0} ${2:-20000}`; do
blockcount=$(( sectionsize * i ));
command="dd if=${REMOTE_DEVICE} bs=1M count=${sectionsize} skip=${blockcount} | gzip"
echo "# section $i (skip $blockcount) command: ${command}"
ssh $REMOTE "${command}" > ${OUTPUT}/image.$i.blob.gz || break
done
#!/bin/sh
# arg 1: start index (default 0)
# arg 2: end index (default 20000)
REMOTE=root@remote-server
REMOTE_DEVICE=/dev/sda
INPUT=/mnt/external/images/0
sectionsize=1024
for i in `seq ${1:-0} ${2:-20000}`; do
blockcount=$(( sectionsize * i ));
command="gzip -cd | dd of=${REMOTE_DEVICE} bs=1M count=${sectionsize} seek=${blockcount}"
echo "# section $i (skip $blockcount) command: ${command}"
cat ${INPUT}/image.$i.blob.gz | ssh $REMOTE "${command}" || break
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment