32

I'm writing a script that does daily snapshots of users' home directories. First I do a dry run using:

rsync -azvrn --out-format="%M %f" source/dir dest/dir

and then the actual rsync operation (by removing the -n option).

I'm trying to parse the output of the dry run. Specifically, I'm interested in learning the exact cause of the rsync error (if one occurred). Does anyone know of

  1. The most common rsync errors and their codes?
  2. A link to a comprehensive rsync error code page?

Most importantly, rsync (at least on CentOs 5) does not return an error code. Rather it displays the errors internally and returns with 0. Like thus:

sending incremental file list
rsync: link_stat "/data/users/gary/testdi" failed: No such file or directory (2)

sent 18 bytes  received 12 bytes  60.00 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)

rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]

Has anyone had to parse rsync errors and have a suggestion on how to store the rsync return state(s)? I believe, when transferring multiple files, that errors may be raised on a per file basis and are collected at the end as shown on the last line of code above.

seebiscuit
  • 4,905
  • 5
  • 31
  • 47

1 Answers1

64

Per the rsync "man" page, here are the error codes it could return and what they mean. If you're scripting it in bash, you could look at $?

 0     Success
 1     Syntax or usage error
 2     Protocol incompatibility
 3     Errors selecting input/output files, dirs
 4     Requested action not supported: an attempt was made to manipulate 64-bit
       files on a platform that cannot support them; or an option was specified
       that is supported by the client and not by the server.
 5     Error starting client-server protocol
 6     Daemon unable to append to log-file
10     Error in socket I/O
11     Error in file I/O
12     Error in rsync protocol data stream
13     Errors with program diagnostics
14     Error in IPC code
20     Received SIGUSR1 or SIGINT
21     Some error returned by waitpid()
22     Error allocating core memory buffers
23     Partial transfer due to error
24     Partial transfer due to vanished source files
25     The --max-delete limit stopped deletions
30     Timeout in data send/receive
35     Timeout waiting for daemon connection

I've never seen a comprehensive "most common errors" list but I'm betting error code 1 would be at the top.

iandouglas
  • 4,146
  • 2
  • 33
  • 33
  • I didn't realize that the man page had this list! Thanks iandouglas. Btw, I'm parsing it on Python. Do you happen to know what is the pythonic equivalent of '$?'? – seebiscuit Dec 23 '13 at 06:25
  • Yeah, if you're using subprocess.call, check this page: http://www.python.org/doc//current/library/subprocess.html#replacing-os-system nutshell: `return_code = subprocess.call(...)` – iandouglas Dec 23 '13 at 06:28
  • 2
    I noticed that `rsync` is funny about returning error codes to the shell. For example, I fed it an incorrect source directory and internally `rsync` reported 2 errors: `rsync: link_stat "/data/users/gary/testdi" failed: No such file or directory (2)` and `rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]`. Yet, printing $? at the shell immediately after the call returned 0. – seebiscuit Dec 23 '13 at 06:39
  • Very odd indeed. If it's always going to give you `(code ##)` in the message, you could just regex for that, perhaps. – iandouglas Dec 23 '13 at 06:50
  • 3
    just to confirm what @Seebiscuit observed, which is indeed odd. If rsync fails during a run because the destination runs out of space this generates (lots of) messages ending `: No space left on device (28)` but it then states `rsync error: error in file IO (code 11) at receiver.c(389) [receiver=3.1.0]` and ends with exit code 11. Seems like the list of error codes in man is a 'meta list' and there are more internal error codes (e.g. 28) which are not however reported back to the shell. – scoobydoo Mar 31 '15 at 06:48
  • Got `rsync error: no space on remote server (code 41) at io.c(1273) [sender=3.0.9]` – Heinrich Ulbricht Sep 06 '17 at 19:04
  • After the source went offline while rsync was running I got `rsync: [sender] write error: Broken pipe (32) ... rsync error: unexplained error (code 255)` – mgutt Dec 19 '21 at 11:03