Hello ya'll,
I stumbled over here looking for some help with Bash shell scripts..
See, the problem was I needed to copy a data DVD into (onto?) the system file space. Since this is a virtual machine, copying a DVD takes a very long time, the drive gets hot, starts dispensing error codes instead of data bits, and I abort the copy process somewhere in the middle.

Looking at the destination directory I can see where the copy process stopped, but I couldn't figure out how to restart it at that point.

I've always had trouble with abstract symbols and need a concrete example to work on, so I'll post what worked for me. Perhaps it will be the hint you are looking for.

for x in m n o p q r s t
do
cp -Rv "/Src_dir/"$x destination_dir
done

Another example:

for x in etc home data usr/local usr/share
do
cp -Rv /$x /system/backup
done

would copy those directories, and everything 'underneath to the system backup directory
Ok, so I don't really know why the drive spits out errors, but the copy command often fails to copy the entire dvd. Being able to restart, or copy only a portion of the dvd file structure was what I needed to do.

PIMF as is Google
regards

Dani AI

Generated

’s idea of copying top‑level directories to be able to restart is a practical quick fix, and ’s suggestion to insert pauses between large copies can reduce transient errors. For a reliable, resumable workflow that survives read errors (rather than just slowing things down), make a raw image of the disc with a tool that records progress and can retry bad sectors; then copy files from the image. That avoids repeated slow hardware reads and makes verification straightforward.

Create an image and a mapfile with GNU ddrescue (mapfile lets the operation be resumed safely):

sudo apt-get install gddrescue
sudo ddrescue -n -b 2048 /dev/sr0 dvd.iso dvd.map
sudo ddrescue -r 3 -b 2048 /dev/sr0 dvd.iso dvd.map

The first command does a fast uncrowded pass; the second retries bad sectors. The mapfile keeps track of what’s been recovered so the job can be resumed without re-reading good areas.

Mount the resulting ISO and copy with rsync so already-copied files are skipped and partial transfers are preserved:

sudo mkdir -p /mnt/iso
sudo mount -o loop dvd.iso /mnt/iso
rsync -a --progress --partial /mnt/iso/ /system/backup/

Notes and cautions: ensure the target has enough free space for the ISO; confirm device name (here /dev/sr0) before running; --inplace or --append-verify can allow resuming single large files but have tradeoffs—use only if familiar. If the virtual machine adds overhead, perform the imaging on the host and attach the ISO to the VM. If read errors persist after retries, try a different drive or a fresh disc; always record a checksum (for example sha256sum dvd.iso) to verify integrity.

> cp -Rv "/Src_dir/"$x destination_dir
As a cheap and easy work-around, how about

cp -Rv "/Src_dir/"$x destination_dir
sleep 120

That is, between each top-level directory, sleep for a couple of minutes to allow things to cool down a bit.

re: sleep 120

Thanks for the tip

I have no way to tell if it was heat related, or something else. Copying those files off of the DVD was taking so long I considered abandoning the project completely. But once I had a way to resume an interrupted copy, I soldier on.

It seems that every time you solve one problem, 6 more appear.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.