Skip to content

Instantly share code, notes, and snippets.

@harishkannarao
Created November 15, 2018 15:18
Show Gist options
  • Save harishkannarao/217d677ecb374115bdc648dd89c9ab2c to your computer and use it in GitHub Desktop.
Save harishkannarao/217d677ecb374115bdc648dd89c9ab2c to your computer and use it in GitHub Desktop.
Practical rsync command and options

Copy new files from source to target and skip files if it already exist in target

rsync --dry-run -avzurh --stats --delete --progress /tmp/source/ /tmp/target/

Explanation of flags:

  • -a -> Archive mode, preserve the file system properties
  • -v -> Verbose output
  • -z -> Use compression mode for data transfer, speeds up for transfer over network
  • -h -> Output in human readable format
  • -u -> Skip if a file already exist in target directory, makes it efficient to copy only the missing files in target directory. Without this flag, it will overwrite the file in the target directory
  • -r -> recursive mode, copies subdirectory
  • --delete -> delete the additional files or directories which are present in target directory which are not present in source directory
  • --dry-run -> do a dry run without making any changes to the file system
  • --stats -> give the stats at the end of the process
  • --progress -> show progress while copying the files

Examples

Copy the source directory itself into the target directory (missing trailing slash at the end)

rsync -avzurh /tmp/source /tmp/target

Copy from local source directory to remote directory

rsync -avzurh /tmp/source/ [email protected]:/tmp/remote-target/

Copy from remote source directory to local target directory

rsync -avzurh [email protected]:/tmp/remote-source/ /tmp/target/

Copy from remote source directory to remote target directory

rsync -avzurh [email protected]:/tmp/remote-source/ [email protected]:/tmp/remote-target/

Include and Exlcude

Copies all files except logs

rsync -avzurh --exclude '*.log' /tmp/source/ /tmp/target/

Copies all files except logs files, but includes only important logs

rsync -avzurh --include '*important*.log' --exclude '*.log' /tmp/source/ /tmp/target/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment