Last active
May 7, 2023 14:52
-
-
Save akatrevorjay/9f6d1c83107fcdf4fed28d298769cfe0 to your computer and use it in GitHub Desktop.
Resume partial dd transfer
This file contains hidden or 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 -e | |
# Blocksize to truncate to and buffer by | |
BS=${BS:-4096} | |
SELF="`basename $0`" | |
death() { echo "$SELF:" "$@" >&2; exit 1; } | |
[ $# -eq 2 ] || death "Usage: $SELF original copy" | |
SRC="$1"; DST="$2" | |
# Got SRC? | |
[ -f "$SRC" ] || death "$SRC: No such file" | |
# Calculate the number of $BS to skip before we start copying. Default to zero. | |
SKIP=0; [ ! -f "$DST" ] || SKIP=$(( $(wc --bytes "$DST" | awk '{print $1}' ) / $BS )) | |
# Do the actual copying. | |
dd if="$SRC" of="$DST" conv=notrunc bs=$BS skip=$SKIP seek=$SKIP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI, there is an issue, as dd is always copying the last (partial) block of the file, because of rounding.
I'm looping over a big list of big files, and have to resume a lot, and that "bug" is not ideal.
Here's how I corrected it :
Granted I could have reused DSTSIZE in the SKIP calculation, but got lazy.
Note also I added the
status=progress
todd
to fit my personal preferences.