I have thousands of pictures (raw) in my computer sorted out into many folders and subfolders. I want to copy those into cloud drive. I successfully mounted to cloud drive. Due to my limited upload bandwidth it may take couple of days to complete the upload. When I am trying to copy files using nautilus, some times the copy process just pauses due to network disconnect for a second of more so nautilus not able to copy a file. I need to take action (skip file and make note of that file) so the copy process will resume. I copied around 1000 files last night and the copy process was interrupted couple of times. After copy process is completed, I manually copied those skipped files, some times those skipped files are partially copied to destination, so I had to overwrite that file. I cant sit at computer for hours to check if the copy process is paused for some reason. I would like to automate this copy process using shell script.

Can you guys recommend the commands for this process so I can build a shell script? I need help in

  1. Should copy all files and folders, sub-folders
  2. It would be nice if copy process show some kind of progress so I know how much is completed.
  3. If the file exists at destination, it should overwrite it automatically.
  4. If the copy process is interrupted, it should try again for couple of times.
  5. If still fails, it should log the file details so I can examine later.
  • The upload destination is correctly mounted into the file system, so we can just copy the same way like to a local folder, right? – Byte Commander Feb 15 '16 at 13:17
  • Yes, we can copy just like into a local folder. I always used GUI to copy and GUI copy pauses when ever it encounter an error. I would like to write a shell script so it will handle the copy errors – Green Star Feb 15 '16 at 13:51
  • 1
    Read man cp, read info coreutils 'cp invocation'. You can answer all your questions by doing that. – waltinator Feb 15 '16 at 15:05
  • 1
    @waltinator: nope, he needs rsync not cp... :P ;-) – Fabby Feb 15 '16 at 23:35

What you need is a single command: rsync

To do the very fist copy do a:

cd path/to/local/directory
rsync --verbose --recursive --progress /path/to/cloud

Whenever you get disconnected or want to update, just do a:

cd path/to/local/directory
rsync --verbose --recursive --progress --update /path/to/cloud

For more bells and whistles: man page here.

  • As you've never accepted an answer on this site before: If this answer helped you, don't forget to click the grey at the left of this text, which means Yes, this answer is valid! ;-) – Fabby Feb 15 '16 at 23:34
  • 1
    Some progress output could be added using the --progress flag. – Byte Commander Feb 16 '16 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.