How to copy files and directories to a remote host without rewrite a directory, just creating new ones

scp

I tried to use scp to that task but unfortunately doesn't work, maybe i have a wrong idea if scp can do that
Anyone can bring me some light?
I read about rsync but i can't understand if rsync can just create directories without overwrite than was i need.
I mean i need some command to put new directories doing sync with the remote host without overwrite files and directories. sorry my english fellows.
Regards
Sebastian

Best Answer

If I'm understanding you correctly, rsync is definitely what you want. Let's say you have a source of:

  • Parent Folder
    • Sub-Folder A
      • File A1
      • File A2
      • File A3
    • Sub-Folder B
      • File B1
      • File B2
      • File B3

and a destination of:

  • Parent Folder
    • Folder A
      • File A1
    • Folder B
      • File B2

If you want to only copy the files that don't already exist in the destination, the --ignore-existing flag (rsync -av --ignore-existing /source user@host:/dest) will only copy the files not already in the destination directory. This will copy Files A2 A3, B1, and B3 to the appropriate place on the new host. However, if you are wanting to copy files A1 and B2 if they have been updated, leaving off the --ignore-existing flag will copy all new and updated files to the destination, but won't copy any files that haven't been modified (based on size and modification timestamp by default). There are many additional options that can be found in the rsync man page.

As a note, the -av flags are for --archive and --verbose. Archive mode enables recursion, preserves as much file metadata as possible (such as ownership, timestamps, etc.), and copies symlinks. Verbose just enables progress notification and other copy information, as rsync is silent by default. You can add additional v's for more information (more than two is intended for debugging the software).

Related Question