rsyncでファイル転送を行った後にどのファイルが転送されたのか確認したい場合があります。
rsyncには--log-file
がありこれを指定すればログを書き出してくれます。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@host01 ~]# rsync -avz -delete --log-file=/var/log/rsync-`date +"%Y%m%d-%H%M"`.log -e ssh --rsync-path="sudo rsync" matsuoka@host02:/usr/local/src/testdata/ /usr/local/src/testdata receiving incremental file list created directory /usr/local/src/testdata ./ .gitignore README.md (snip) html/ html/index.php html/htdocs/ sent 486 bytes received 530434 bytes 1061840.00 bytes/sec total size is 613207 speedup is 1.15 |
ログを確認してみます。
1 2 3 4 5 6 7 8 9 10 11 12 |
[root@host01 ~]# cat /var/log/rsync-20160129-1349.log 2016/01/29 13:49:58 [3479] receiving file list 2016/01/29 13:49:58 [3479] created directory /usr/local/src/testdata 2016/01/29 13:49:58 [3481] cd+++++++++ ./ 2016/01/29 13:49:58 [3481] >f+++++++++ .gitignore 2016/01/29 13:49:58 [3481] >f+++++++++ README.md (snip) 2016/01/29 13:49:58 [3481] cd+++++++++ html/ 2016/01/29 13:49:58 [3481] >f+++++++++ html/index.php 2016/01/29 13:49:58 [3481] cd+++++++++ html/htdocs/ 2016/01/29 13:49:58 [3481] sent 486 bytes received 530434 bytes 1061840.00 bytes/sec 2016/01/29 13:49:58 [3481] total size is 613207 speedup is 1.15 |
default formatは”%i %n%L”ですが最初に”%t [%p] “が必ず付きます。
従って上記ログは”日時 [プロセスID] アップデート項目 ファイル名 Linkファイル”になります。
出力項目を変更する時は--log-file-format
を使用します。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@host01 ~]# rsync -avz -delete --log-file=/var/log/rsync-`date +"%Y%m%d-%H%M"`.log --log-file-format="%o %f (%U %B) %l %b" -e ssh --rsync-path="sudo rsync" matsuoka@host02:/usr/local/src/testdata/ /usr/local/src/testdata receiving incremental file list created directory /usr/local/src/NetCommons-2.4.2.1 ./ .gitignore README.md (snip) html/ html/index.php html/htdocs/ sent 486 bytes received 530434 bytes 353946.67 bytes/sec total size is 613207 speedup is 1.15 |
--log-file-format="%o %f (%U %B) %l %b"
を指定しているので
“日時 [プロセスID] 処理 ファイル名 (UID パーミッション) ファイルサイズ 実転送サイズ”
になります。-zを指定しているので圧縮転送が行われているのが分かります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[root@host01 ~]# cat /var/log/rsync-20160129-1505.log 2016/01/29 15:05:53 [3700] receiving file list 2016/01/29 15:05:53 [3700] created directory /usr/local/src/testdata 2016/01/29 15:05:53 [3700] ./ 2016/01/29 15:05:53 [3700] docs/ 2016/01/29 15:05:53 [3700] docs/img/ 2016/01/29 15:05:53 [3700] html/ 2016/01/29 15:05:53 [3700] html/htdocs/ 2016/01/29 15:05:53 [3702] recv . (0 rwx------) 61 0 2016/01/29 15:05:53 [3702] recv .gitignore (0 rw-r--r--) 1249 661 2016/01/29 15:05:53 [3702] recv README.md (0 rw-r--r--) 45 66 (snip) 2016/01/29 15:05:53 [3702] recv html (0 rwxr-xr-x) 35 0 2016/01/29 15:05:53 [3702] recv html/index.php (0 rw-r--r--) 2348 1282 2016/01/29 15:05:53 [3702] recv html/htdocs (0 rwxr-xr-x) 6 0 2016/01/29 15:05:53 [3702] sent 486 bytes received 530434 bytes 353946.67 bytes/sec 2016/01/29 15:05:53 [3702] total size is 613207 speedup is 1.15 |
man rsyncから抜粋
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
--log-file=FILE This option causes rsync to log what it is doing to a file. This is similar to the logging that a daemon does, but can be requested for the client side and/or the server side of a non- daemon transfer. If specified as a client option, transfer log- ging will be enabled with a default format of “%i %n%L”. See the --log-file-format option if you wish to override this. Here’s a example command that requests the remote side to log what is happening: rsync -av --rsync-path="rsync --log-file=/tmp/rlog" src/ dest/ This is very useful if you need to debug why a connection is closing unexpectedly. --log-file-format=FORMAT This allows you to specify exactly what per-update logging is put into the file specified by the --log-file option (which must also be specified for this option to have any effect). If you specify an empty string, updated files will not be mentioned in the log file. For a list of the possible escape characters, see the “log format” setting in the rsyncd.conf manpage. The default FORMAT used if --log-file is specified and this option is not is ’%i %n%L’. |
man rsyncd.confから抜粋
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
log file When the “log file” parameter is set to a non-empty string, the rsync daemon will log messages to the indicated file rather than using syslog. This is particularly useful on systems (such as AIX) where syslog() doesn’t work for chrooted programs. The file is opened before chroot() is called, allowing it to be placed outside the transfer. If this value is set on a per-mod- ule basis instead of globally, the global log will still contain any authorization failures or config-file error messages. If the daemon fails to open the specified file, it will fall back to using syslog and output an error about the failure. (Note that the failure to open the specified log file used to be a fatal error.) log format This parameter allows you to specify the format used for logging file transfers when transfer logging is enabled. The format is a text string containing embedded single-character escape sequences prefixed with a percent (%) character. An optional numeric field width may also be specified between the percent and the escape letter (e.g. “%-50n %8l %07p”). The default log format is “%o %h [%a] %m (%u) %f %l”, and a “%t [%p] ” is always prefixed when using the “log file” parameter. (A perl script that will summarize this default log format is included in the rsync source code distribution in the “support” subdirectory: rsyncstats.) The single-character escapes that are understood are as follows: o %a the remote IP address o %b the number of bytes actually transferred o %B the permission bits of the file (e.g. rwxrwxrwt) o %c the total size of the block checksums received for the basis file (only when sending) o %f the filename (long form on sender; no trailing “/”) o %G the gid of the file (decimal) or “DEFAULT” o %h the remote host name o %i an itemized list of what is being updated o %l the length of the file in bytes o %L the string “ -> SYMLINK”, “ => HARDLINK”, or “” (where SYMLINK or HARDLINK is a filename) o %m the module name o %M the last-modified time of the file o %n the filename (short form; trailing “/” on dir) o %o the operation, which is “send”, “recv”, or “del.” (the latter includes the trailing period) o %p the process ID of this rsync session o %P the module path o %t the current date time o %u the authenticated username or an empty string o %U the uid of the file (decimal) For a list of what the characters mean that are output by “%i”, see the --itemize-changes option in the rsync manpage. Note that some of the logged output changes when talking with older rsync versions. For instance, deleted files were only output as verbose messages prior to rsync 2.6.4. |