Upgrade to Pro — share decks privately, control downloads, hide ads and more …

rsync 3.2.0 の新機能を試す

rsync 3.2.0 の新機能を試す

"鹿児島Linux勉強会 2020.06(オンライン開催) - connpass" https://kagolug.connpass.com/event/179564/
で発表したもの

Kenichiro MATOHARA

June 28, 2020
Tweet

More Decks by Kenichiro MATOHARA

Other Decks in Technology

Transcript

  1. 3 / 29 最近 • Epic Gamesで貰ったWindows用ゲームを動かし たり • Linux環境で(低解像度の)画面共有を行うTipsを発

    表したら失敗したり (Zoom.us……) • Vanity Addressesを計算したり • cow を増やしたり • SpeakerDeckが非公開になったり
  2. 4 / 29 rsync 3.2.0 release • samba プロジェクトのファイル同期ソフトウェア •

    ファイルの単方向コピー,差分コピーに便利 – サーバ間だけでなく PC ,スマートフォンからの バックアップ等日常的にお世話になっている – Apple TimeMachineのような同期(--link-dest) やリアルタイム同期も • rsyncd もあるけど暗号化されないので ssh や rsync-ssl などを利用する ( そういばscp(1)非推奨の流れも→ sftp/rsync)
  3. 5 / 29 • rsync 3.2.0 は大体 1 年半ぶりのリリース •

    Protocol は 31 で据え置きだけど新機能が結構入っ ているように見えるので試してみた ※ これから試す人は最新をチェック ( 少なくとも 3.2.1 が出ている )
  4. 6 / 29 導入例 • Debian sid amd64 $ sudo

    apt install rsync • Ubuntu 20.04 LTS amd64 build-dep して source から • Raspberry Pi OS arm64(Debian stretch ベース ) zstd ライブラリも source から導入する必要あり ( 若しくは configure 時に --disable-zstd)
  5. 7 / 29 Debian sid amd64/Ubuntu 20.04 LTS amd64 へ

    source から $ sudo apt build-dep rsync #rsync build に必要なパッケージ導入 $ sudo apt install libxxhash-dev libzstd-dev liblz4-dev $ wget -c \ #source 入手 https://download.samba.org/pub/rsync/rsync-3.2.0.tar.gz \ https://download.samba.org/pub/rsync/rsync-3.2.0.tar.gz.asc \ https://opencoder.net/WayneDavison.key $ gpg2 --import ./WayneDavison.key # 鍵のインポート $ gpg2 --verify ./rsync-3.2.0.tar.gz.asc # ファイル検証 #source 展開 $ tar tvzf ./rsync-3.2.0.tar.gz $ tar xzf ./rsync-3.2.0.tar.gz #source 展開 $ cd rsync-3.2.0 $ ./configure –help $ ./configure $ make
  6. 8 / 29 Raspberri Pi OS amd64 $ sudo apt

    remove libzstd-dev # 古いパッケージ削除 $ wget \ #zstdsource 入手 https://github.com/facebook/zstd/releases/download/v1.4.5/ zstd-1.4.5.tar.gz \ https://github.com/facebook/zstd/releases/download/v1.4.5/zstd -1.4.5.tar.gz.sha256 $ sha256sum -c ./zstd-1.4.5.tar.gz.sha256 $ tar tvf ./zstd- 1.4.5.tar.gz #hash 確認 $ tar xf ./zstd-1.4.5.tar.gz #source 展開 $ cd zstd-1.4.5 $ make $ sudo make install $ cd ../rsync-3.2.0 $ ./configure && make
  7. 9 / 29 $ rsync --version rsync version 3.2.0 protocol

    version 31 Copyright (C) 1996-2020 by Andrew Tridgell, Wayne Davison, and others. Web site: http://rsync.samba.org/ Capabilities: 64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints, socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace, append, ACLs, xattrs, iconv, symtimes, prealloc, SIMD Checksum list: xxh64 (xxhash) md5 md4 none Compress list: zstd lz4 zlibx zlib none rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the GNU General Public Licence for details.
  8. 11 / 29 気になる BUG FIX • Avoid a hang

    when an overabundance of messages clogs up all the I/O buffers. • これも直った ?( 未確認 ) FAT32 の制限に引っかかると rsync が帰ってこ ない→ --timeout= オプションを付けた – "HDD データ復旧時に FAT32 の制限に嵌ったメ モ – matoken's meme" https://matoken.org/blog/2020/04/11/notes-o n-fat32-when-recovering-hdd-data/
  9. 13 / 29 --checksum-choice=STR, -- cc=STR • チェックサム形式を選べるようになった • 現在選択できるのは

    xxh64/md5/md4 の 3 種類 or none or auto( 既定値 ) • --version にも出力される $ rsync --version | grep Checksum -A1 Checksum list: xxh64 (xxhash) md5 md4 none • configure option に --disable-xxhash
  10. 14 / 29 • 環境変数 RSYNC_CHECKSUM_LIST でも指定でき る.オプション --checksum-choice が優先

    • --checksum-choice オプションに対応していない 3.1.3 に対して xxh64 を向けて叩いてみると以下 のようなエラー (md4, md5 は ok) $ rsync --checksum-choice=xxh64 -avc ./* user@remote:/tmp/ unknown checksum name: xxh64 rsync error: requested action not supported (code 4) at checksum.c(73) [server=3.1.3] rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: error in rsync protocol data stream (code 12) at io.c(235) [sender=3.2.0]
  11. 15 / 29 ハッシュ簡易ベンチ • kernel source の hash 突き合わせ

    ( 小さいファイル沢山 ) $ rsync --checksum-choice=auto -ac ./linux-5.6 /tmp/ $ sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches ; time rsync --checksum- choice=md4 -ac ./linux-5.6 /tmp/
  12. 16 / 29 小さいファイル沢山 (time コマン ドの real 値 )

    $ find ./linux-5.6 | wc -l 82114 $ du -ms ./linux-5.6 1310 ./linux-5.6 • md4 52.393s • md5 57.716s • xxh64 1m5.520s
  13. 17 / 29 大きなファイル 1 つ ( 約 4GB x1)

    $ ls -s ./Parrot-security-4.9.1_x64.iso* 3909164 ./Parrot-security-4.9.1_x64.iso 3909164 ./Parrot-security-4.9.1_x64.iso2 • md4 23.276s • md5 28.150s • xxh64 12.767s ※Raspberry Pi 3B(RAM1GB) + arm64 OS でも同じ 傾向, XXH64 は32bitだと遅くなるはず(XXH32?)
  14. 18 / 29 --compress-choice=STR, -- zc=STR • 圧縮形式を指定できる • 選択できるオプションは

    zstd, lz4, zlibx, zlib, none • rsync --version でも確認できる $ rsync --version | grep Compress -A1 Compress list: zstd lz4 zlibx zlib none • configure oprion に --disable-zstd, --disable-lz4 • 環境変数 RSYNC_COMPRESS_LIST も
  15. 19 / 29 圧縮形式簡易ベンチ $ ssh user@remote rm -rf ~/tmp/linux-5.6;

    echo 3 | sudo tee /proc/sys/vm/drop_caches; time rsync -- compress-choice=zstd --compress -a --rsync-path=~/ src/rsync-3.2.0/rsync ~/src/linux-5.6 user@remote:~/ tmp/ • 圧縮を有効にしてリモートコピー
  16. 20 / 29 結果 (time コマンドの real 値 ) •

    zstd 4m38.921s • lz4 9m28.829s • zlibx 5m21.702s • zlib 5m28.722s • none 22m56.712s
  17. 22 / 29 --debug=OPTS, -M—​ debug=OPTS • --debug=OPTS を使うとリモートの rsync

    にデ バッグオプションを送らなくなる • -M—​ debug=OPTS でリモートにデバッグオプショ ンを送れる • 組み合わせるとローカルとリモートで別々のデバッ グレベルを指定できる
  18. 23 / 29 SIGINFO & SIGVTALRM • rsync プロセスに SIGINFO

    & SIGVTALRM シグナ ルを送信することでステータスを表示できるように なった • Linux は SIGINFO に対応していない • rsync を実行している状態で SIGVTALRM を送信 $ pkill -SIGVTALRM rsync • rsync がステータスを表示 linux-5.6/arch/sparc/lib/lshrdi3.S 114,384,392 81% 931.12kB/s 0:01:59 (xfr#21058, ir-chk=1030/23451)
  19. 24 / 29 --copy-as=USER[:GROUP] • 指定ユーザ / グループ権限でファイルをコピー • コピー元に

    3 ユーザのファイル – $ ls -Al /tmp/rsync-test/ – total 0 – -rw-r--r-- 1 matoken matoken 0 Jun 25 18:50 matokenfile – -rw-r--r-- 1 root root 0 Jun 25 18:51 root – -rw-r--r-- 1 www-data www-data 0 Jun 25 18:51 www-data • 普通にコピーするとユーザ,グループが引き継がれ る
  20. 25 / 29 • --copy-as=matoken を指定するとすべて matoken になる $ sudo

    \rm -rf /tmp/rsync-test2 $ sudo ./rsync --copy-as=matoken -a /tmp/rsync-test/ /tmp/rsync- test2 $ ls -lA /tmp/rsync-test2 total 0 -rw-r--r-- 1 matoken matoken 0 Jun 25 18:50 matokenfile -rw-r--r-- 1 matoken matoken 0 Jun 25 18:51 root -rw-r--r-- 1 matoken matoken 0 Jun 25 18:51 www-data
  21. 27 / 29 --ipv4, -4 / --ipv6, -6 • ipv4,

    ipv6 を指定したいときに rsh='ssh -4' とす るより便利
  22. 28 / 29 まとめ • --checksum-choice=xxh64, --compress-choice=zstd, -- debug=OPTS が特に便利そう

    • 時間は環境により変わるので注意 • ディストリビューションに入ってくるのは次のバー ジョンくらいから ?Ubuntu は多分 20.10 〜 • 場合によっては Unison とかも便利
  23. 29 / 29 奥付 • 発表 : 「鹿児島Linux勉強会 2020.06」 •

    発表日 : 2020-06-28(sun) • 発表者 : KenichiroMatohara • * License: CC BY-NC-SA 4.0 • * 利用ツール : codium + Marp for VS Code