rsync

rsync

https://linux.die.net/man/1/rsync

rsync -av --ignore-existing source_dir/ dest_dir/

rsync -av --progress --ignore-existing "/cygdrive/c/Users/username/Sync/Photos/" "/cygdrive/p/FromSync/Photos"

Flags

  1. -a (archive): This is a shortcut for several options (-rlptgoD). It means:
    1. -r: Recurse into directories.
    2. -l: Copy symlinks as symlinks.
    3. -p: Preserve permissions.
    4. -t: Preserve modification times.
    5. -g: Preserve group.
    6. -o: Preserve owner (superuser only).
    7. -D: Preserve device files and special files (superuser only).
  2. You usually want -a for directory copying.
  3. -v (verbose): Optional, but recommended. Shows you which files are being transferred. You can add more v’s (e.g., -avv) for more detail.
  4. --ignore-existing: This is the key option. It tells rsync not to update or overwrite any file that already exists in the destination directory (dest_dir), regardless of timestamp or size. It will only copy files from source_dir that are missing in dest_dir.

Dry run

rsync -avn --ignore-existing source_dir/ dest_dir/

With cygwin

rsync -av --progress  --ignore-existing /cygdrive/c/Users/vardh/Sync/temp/ /cygdrive/p/FromSync/temp

The trailing slash

This tells rsync to copy the contents of source_dir into dest_dir. Without it (source_dir), rsync would create dest_dir/source_dir/....

If you use a slash at the end of the first directory, then it means: The contents of sourceDirectory but not the directory itself. On the other hand if you ommit the use of the slash in the sourceDirectory then it means: The content of the sourceDirectory but also the SourceDirectory/ itself.

It is important to understand how a trailing slash on the source argument functions. If there is a trailing slash then the contents of /source-path/source-dir will be copied to destination-path. If there is no trailing slash then source-dir itself will be copied to the destination and its contents will be another level down in the destination hierarchy.

So if you want to replicate one path to another include the trailing slash as follows:

rsync -av /sourcepath/sourcedir/ /duplicatpath/sourcedir/

Links to this note