我在设置从 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" [email protected]:~/
[email protected]'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" [email protected]:~/
[email protected]'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" "[email protected]:~/"
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 . "~/"
[email protected]'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 [email protected]:
[email protected]'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
我缺少什么?
答案1
如果您使用rsync -n
,则不会将任何内容复制到目的地。
-n
的选项与rsync
相同--dry-run
,即“执行试运行而不做任何更改”(措辞取自手册)。
从命令行中删除-n
并重试。