Ubuntu – Using mv & cp on a headless server (SSH timeout interferring?)

command linecpssh

I've recently set up a headless server to back up a number of very large film & editing files.

I SSH into the server and – following some best practice guides I found around – I've tightened security so that the server auto logs me off after 5 minutes of inactivity.

This is now creating a bit of a headache as I try to sort and move those files.

Issuing mv file1 /new_directory/ can take +5 mins and so I'm often logged off half way through.

Where multiple files are involved I've come back to find that some files seem to have transferred and others (at a seemingly arbitrary cut off point… or roughly what I reckon a 5 min timeout might have allowed) have not.

So my questions are:

  1. When issuing a mv command, if it is cancelled whilst incomplete is there any risk of data loss? Might I be safer using cp?
  2. Is there any way that I could set a cp or mv command to go and then be sure that it will continue even after I've logged off or my ssh window has closed
  3. Is there a way to do other things whilst a mv or cp is taking place (and thus refresh my countdown timer)

Best Answer

Don't log in as such. Instead, from your local machine, run

ssh user@server mv /path/to/source /path/to/dest

That should let you get around the problem.

On a more general note, I do believe you are being a bit paranoid here. Setting the idle time to 5 minutes and then facing this kind of issue seems silly. Just set it to something longer and avoid the problem.

As for your 1st question, mv will only delete the source files if the copy succeeded. As explained in info mv (emphasis mine):

It first uses some of the same code that's used by `cp -a' to copy the requested directories and files, then (assuming the copy succeeded) it removes the originals. If the copy fails, then the part that was copied to the destination partition is removed. If you were to copy three directories from one partition to another and the copy of the first directory succeeded, but the second didn't, the first would be left on the destination partition and the second and third would be left on the original partition.

Related Question