#!/bin/bash set -o nounset set -o errexit set -o pipefail readonly ARGS=( "${@}" ); main() { local _input_root; _input_root="${1}"; shift; local _output_root; _output_root="${1}"; shift; local input_root; input_root="$(readlink --canonicalize-existing "${_input_root}")"; local output_root; output_root="$(readlink --canonicalize-missing "${_output_root}")"; local input_length; input_length=$((${#input_root} + 1)); find "${input_root}" -type d -print0 \ | while read -r -d $'\0' d; do local dname; dname="${d:${input_length}}"; local target; target="${output_root}/${dname}"; >&2 echo "*** ${dname}/" mkdir -p "${target}" done >&2 echo "Directory tree restored" find "${input_root}" -type f -print0 \ | while read -r -d $'\0' f; do local fname; fname="${f:${input_length}}"; >&2 echo "+++ ${fname}" ddrescue --quiet "${input_root}/${fname}" "${output_root}/${fname}" done >&2 echo "Done." } main "${ARGS[@]}"