CP followed by RSYNC to copy what was missed

my prefered way to copy is to just use rsync or cp. I noticed cp dies less often (less broken pipes) and when IO errors are encountered it handles it better (although I could be wrong as rsync has a ignore error option)

first make the destination folder

do the first copy
I use -u, that way if a copy stops/cancels/fails, I can repeat the command and it will start where it left off (it will take a few moments for cp to realize where it left off, as it compares whats on source and destination side) – kind of
kind of because it will skip the file it stopped/canceled/failed on, because cp will see the file on the source and on the destination (it doesnt have checks to see if the file fully copied)
this is where rsync comes in afterwards to finish copying what was missed

dry run rsync

this will now show you what copies what were missed with cp, without doing the copy (hence dry run – its basically just a simulation – remove -n to make it not a dry run)

run rsync: when ready for actual run just remove the -names

cp -r: recursive, to get everything in the folders

cp -u: gives you the ability to resume
cp -v: verbose logging. without it we dont see anything on the screen, until its done and we are back at the prompt. if the copy fails, it will be the last file listed.

rsync -u: update, ability to resume half finished files etc…
rsync -a: has alot of options including -r to show you. this also has –progress to give you a progress bar per each file (however you will not see this progress bar until you also include -v)
rsync -v: verbose logging. without it we dont see anything on the screen, until its done and we are back at the prompt. -v is the one that shows any output, then other options add or take away to what it shows
rsync -n: dry run, doesnt do anything, just shows you what it will do, note that -n without -v shows you no output. -v is the one that shows output of any kind.

notice the folder names are not ending with /, this important so that you get the correct tree structure in the end.
here it will be /destinationfolder/folder1 and /destination/folder2

How I would actually run this:

I would run this in the background with nohup

if you have bash version 4 you can log stdout and stderr to same file with &>.

if you have bash 1,2,3 then you can log stdout and stderr but with > /log/copy-date +%s.log 2>&1. the 2>&1 means write errors where you write stdout (stdout and stderr go to same place). Also put the 2>&1 after the >/log/copy-date +%s.log so that it knows where &1 is.

if you have bash version 4 you can log stdout and stderr to same file with &>.

if you have bash 1,2,3 then you can log stdout and stderr but with > /log/rsync-date +%s.log 2>&1

i append the epoch seconds date to the log file. so the log files will be like

Also note that you can put the logfile in the destinationfolder. i.e. /destinationfolder/copy-date +%s.log

The End

Leave a Reply

Your email address will not be published. Required fields are marked *