1

I have SSH access (using a SSH key pair) to a remote machine. I want to keep a directory on the remote machine exactly equal to a given local directory (one way sync). The check for file equality should be done based on a hash of the binary file content (not size/date).

  1. What is the correct rsync command to do that (not rsync service)?
  2. How are file permissions handled?
  3. How are file modification dates handled?
  4. How does rsync react to failures and what is the exit code?

1 Answer 1

1

Rsync checks the contents of the file, not the date and/or file size. If the contents are different but with the same path and name, then the file will be overwritten.

The syntax for rsync is rsync options source destination so if you want to keep a remote directory synced with a local one this should do the trick:

rsync -azh local_folder user@remote_server:/path/to/destination/

If you want to use SSH as a transfer protocol then this works for me:

rsync -azhe ssh local_folder user@remote_server:/path/to/destination

How are file permissions handled? How are file modification dates handled?

The a parameter preserves symlinks, file permissions, timestamps... if you dont want to transfer over this information just exclude it from the command, it will be owned by the user with whom you logged in the SSH session.

How does rsync react to failures and what is the exit code?

Most commands/programs return 0 when success and any other number on error. Here is a list of rsync exit codes for reference

1
  • The statement in the first paragraph of this answer, "Rsync checks the contents of the file, not the date and/or file size" , is false. According to the man page of rsync, "normally rsync will skip any files that are already the same size and have the same modification timestamp". Check the man page for options --ignore-times, --size-only, --checksum, etc.
    – Yingyu YOU
    Commented Mar 20, 2018 at 2:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .