Ssh
Rsync“成功”但實際上通過 ssh 失敗
我在設置從我的 mac 筆記型電腦到 Ubuntu 伺服器時遇到
rsync
問題ssh
。基本上,我的命令行就像外部驅動器的魅力一樣,可以同步目錄並只推送更改的文件。使用
ssh
命令成功但實際上它不會在伺服器上寫入任何內容。這是我用一些無用的基本文件(在 mac 筆記型電腦上)嘗試過的測試:
~% mkdir foobar ~% cd foobar foobar% echo "test1" > a.txt foobar% echo "test2" > b.txt foobar% cd ..
然後是同步:
% rsync -a --delete -h -v -n "/Users/sensei/foobar" senseilinux@ssh.w.name.com:~/ senseilinux@ssh.w.name.com's password: building file list ... done foobar/ foobar/a.txt foobar/b.txt sent 133 bytes received 38 bytes 31.09 bytes/sec total size is 12 speedup is 0.07
命令成功,但如果我
ssh
是一台 linux 伺服器,則什麼都沒有寫入。這也可以通過rsync
第二次執行而不修改任何文件來確認:~% rsync -a --delete -h -v -n "/Users/sensei/foobar" senseilinux@ssh.w.name.com:~/ senseilinux@ssh.w.name.com's password: building file list ... done foobar/ foobar/a.txt foobar/b.txt sent 133 bytes received 38 bytes 38.00 bytes/sec total size is 12 speedup is 0.07
我不知道我在這裡缺少什麼,所以我已經
rsync
冗長地執行了:~% rsync -a --delete -h -vvvvv -n "/Users/sensei/foobar" "senseilinux@ssh.w.name.com:~/" cmd= machine=ssh.w.name.com user=senseilinux path=~/ cmd[0]=ssh cmd[1]=-l cmd[2]=senseilinux cmd[3]=ssh.w.name.com cmd[4]=rsync cmd[5]=--server cmd[6]=-vvvvvnlogDtpr cmd[7]=--delete cmd[8]=. cmd[9]=~/ opening connection using ssh -l senseilinux ssh.w.name.com rsync --server -vvvvvnlogDtpr --delete . "~/" senseilinux@ssh.w.name.com's password: FILE_STRUCT_LEN=24, EXTRA_LEN=4 (Client) Protocol versions: remote=31, negotiated=29 (Server) Protocol versions: remote=29, negotiated=29 building file list ... [sender] make_file(foobar,*,2) [sender] make_file(foobar/b.txt,*,2) [sender] make_file(foobar/a.txt,*,2) done server_recv(2) starting pid=58290 [sender] i=0 /Users/sensei foobar/ mode=040755 len=128 uid=501 gid=20 flags=1 [sender] i=1 /Users/sensei foobar/a.txt mode=0100644 len=6 uid=501 gid=20 flags=0 [sender] i=2 /Users/sensei foobar/b.txt mode=0100644 len=6 uid=501 gid=20 flags=0 send_file_list done file list sent send_files starting recv_file_name(foobar) recv_file_name(foobar/b.txt) recv_file_name(foobar/a.txt) received 3 names uid 501(sensei) maps to 501 process has 2 gids: 27 1034 gid 20(staff) maps to 50 [Receiver] flist_eof=1 [Receiver] flist start=0, used=3, low=0, high=2 [Receiver] i=0 1 foobar/ mode=040755 len=128 gid=(50) flags=405 [Receiver] i=1 2 foobar/a.txt mode=0100644 len=6 gid=(50) flags=400 [Receiver] i=2 2 foobar/b.txt mode=0100644 len=6 gid=(50) flags=400 recv_file_list done get_local_name count=3 /home/senseilinux/ [Receiver] change_dir(/home/senseilinux) generator starting pid=58290 deleting in foobar [generator] pushing local filters for /home/senseilinux/foobar/a.txt/ [generator] pushing local filters for /home/senseilinux/foobar/b.txt/ delta-transmission enabled recv_generator(foobar,0) send_files(0, /Users/sensei/foobar) foobar/ recv_generator(foobar/a.txt,1) recv_generator(foobar/b.txt,2) generate_files phase=1 send_files(1, /Users/sensei/foobar/a.txt) foobar/a.txt send_files(2, /Users/sensei/foobar/b.txt) foobar/b.txt send_files phase=1 recv_files(3) starting recv_files(foobar) recv_files(foobar/a.txt) recv_files(foobar/b.txt) recv_files phase=1 generate_files phase=2 send_files phase=2 send files finished total: matches=0 hash_hits=0 false_alarms=0 data=0 recv_files phase=2 generate_files phase=3 recv_files finished generate_files finished client_run waiting on 12185 sent 133 bytes received 38 bytes 38.00 bytes/sec total size is 12 speedup is 0.07 _exit_cleanup(code=0, file=/BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-52.200.1/rsync/main.c, line=996): entered _exit_cleanup(code=0, file=/BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-52.200.1/rsync/main.c, line=996): about to call exit(0)
顯然,一切都很好。但是,伺服器上什麼都沒有。
不僅如此,如果我向伺服器送出文件完全沒有問題:
scp
~% scp -r foobar senseilinux@ssh.w.name.com: senseilinux@ssh.w.name.com's password: b.txt 100% 6 0.5KB/s 00:00 a.txt 100% 6 0.5KB/s 00:00 # ON THE LINUX SERVER: ~$ ls foobar/ a.txt b.txt
我錯過了什麼?
如果您使用
rsync -n
,則不會將任何內容複製到目的地。
-n
選項rsync
與 相同,即“在不做任何更改的--dry-run
情況下進行試執行”(措辭取自手冊)。
-n
從命令行中刪除並重試。