@peccul is peccu

(love peccu '(emacs lisp cat outdoor bicycle mac linux coffee))

ローカルのディレクトリとリモートのディレクトリを比較したい

ファイルだとググってすぐ出てきたけど、ディレクトリだとパッと出てこなかった。

ファイルの場合

diffでファイルの差分ならsshとcatの組み合わせをdiffに流してあげればよいみたい。

serverfault.com

diff local/path/to/foo <(ssh myServer 'cat remote/path/to/foo')

ディレクトリの場合(案)

rsyncで変更のあったファイルを列挙して、上記ファイルの場合を利用してみた。

# need trailing slash
localPath=some/path/to/dir/
remoteServer=myServer
remotePath=some/remote/path/to/dir/

for i in $(rsync -c --dry-run --delete --exclude='*~' -avz $localPath $remoteServer:$remotePath | grep -ve '/$' | grep -ve '^deleting \|^building \|^$\|^sent \|^total size is ')
do
echo showing diff $i
diff -u $localPath$i <(ssh $remote "cat $remotePath$i")
done

rsync-cオプションがファイルの変更をサイズや変更日時ではなく、チェックサムで比較するオプション。

あとはrsyncの出力を無理やりファイルだけに限定している。(buildingほげほげとか、deleting filenameとか、最後のサマリをgrepで消してる)

サーバーにはなくて、ローカルには存在するファイルはファイル全体が変更行として出力される。