From a356b2d303137a9c05ece0197dcff925ffc4244f Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 2 Jan 2014 15:34:02 -0500 Subject: [PATCH] backup-dvd: handle errors --- .bin/backup-dvd | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/.bin/backup-dvd b/.bin/backup-dvd index a4dfdab..ef79dde 100755 --- a/.bin/backup-dvd +++ b/.bin/backup-dvd @@ -11,6 +11,7 @@ usage() { -n Defaults to volume on disk Commands: + --errors Image the raw disc first w/ddrescue --backup Back up the disc --modify Tweak runtime settings (needs -n) --mkiso Create an iso (needs -n) @@ -25,8 +26,9 @@ out=${PWD} vol= unset doit_{backup,modify,mkiso} +doit_errors=false -eval set -- `getopt -l backup,modify,mkiso -- hi:n:o: "$@"` +eval set -- `getopt -l errors,backup,modify,mkiso -- hi:n:o: "$@"` while [[ -n $1 ]] ; do case $1 in -h) usage;; @@ -34,6 +36,7 @@ while [[ -n $1 ]] ; do -o) out=$2; shift 2;; -n) vol=$2; shift 2;; + --errors) doit_errors=true; shift;; --backup) doit_backup=true; shift;; --modify) doit_modify=true; shift;; --mkiso) doit_mkiso=true; shift;; @@ -98,16 +101,32 @@ e() { "$@" } +# +# Mirror the disc w/ddrescue which tolerates errors. +# +raw_read_dvd() { + echo "Imaging disc" + local raw=".${Volume}.raw" + local log="${raw}.log" + local opts=( + -v -b 2048 ${dev} "${raw}" "${log}" + ) + ddrescue -p -n "${opts[@]}" + ddrescue -d -r 3 "${opts[@]}" + ddrescue -d -r 3 -R "${opts[@]}" + dev=${raw} +} + # # Backup the disc. # -opts=( - -i ${dev} - -o "${out}" - -n "${Volume}" -) backup_dvd() { echo "Backing up: ${Volume}" + local opts=( + -i ${dev} + -o "${out}" + -n "${Volume}" + ) if ! e dvdbackup -M "${opts[@]}" ; then e dvdbackup -F "${opts[@]}" || exit 1 fi @@ -298,6 +317,11 @@ modify_dvd() { local out_vts_dir="${out}/${Volume}/VIDEO_TS" local vmgi vtsi + if ${doit_errors} ; then + echo "skipping modifications due to possible errors in files" + return + fi + for vmgi in "${out_vts_dir}"/VIDEO_TS.{IFO,BUP} ; do process_vmgi "${vmgi}" check_changes "${vmgi}" || exit 1 @@ -335,8 +359,10 @@ mkiso_dvd() { "${sh}" || exit du -h "${out}/${Volume}.iso" + sudo chattr +i "${out}/${Volume}.iso" } +${doit_errors} && raw_read_dvd ${doit_backup} && backup_dvd ${doit_modify} && modify_dvd ${doit_mkiso} && mkiso_dvd -- 2.39.5