Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
    
Thnx guys for your answers, but if i need to copy also directories with this command will do exactly than i need? i mean... i have to copy only new files and new directories to destiny Regards.. –  debianita Jul 18 '12 at 17:17
    
the recursive bit in the -a parameter means it will include subdirectories. If you add a trailing slash (folder/ instead of folder), it will only copy the contents of the parent. Without the slash, the parent folder will be copied too. Does that answer your question? –  ND Geek Jul 19 '12 at 1:25
    
Thank you very much ND Geek for your expertise.. –  debianita Jul 19 '12 at 15:22
add comment

1 Answer

up vote 1 down vote accepted

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).

share|improve this answer
    
note: to use rsync via ssh, call it with the --rsh=ssh parameter. Behaviour will be the same as described by ND Geek -- but you might need ssh to reach the other machine safely. The equivalent shortcut-parameter would be -e ssh. –  Izzy Jul 18 '12 at 9:38
    
@Izzy thanks...I knew I was forgetting something! –  ND Geek Jul 19 '12 at 1:18
    
Although this is a good method, it is only useful if you control both sides. If the target machine is windows, the account only has sftp/scp priv, or rsync is not installed on the target machine, this method will not work. The closest i've found is using a find with a rm execute after fully uploaded. Unless you write a program/script to record what you've already uploaded successfully. –  Rahly Jun 10 at 20:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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