当r-同步VirtualBox目录时,我的期望脚本无法继续。在期望脚本中同步VirtualBox目录时rsync挂起
下面是脚本:
#!/usr/bin/expect -f
spawn rsync -vruEtl --progress -h --log-file=rsync.log --fuzzy --stats /home/james/Documents/ [email protected]:/home/username/BAK/Documents/
expect "password:"
send "thepassword\r"
interact
sleep 1
spawn rsync -vruEtl --progress -h --log-file=rsync.log --fuzzy --stats /home/james/AndroidDev/ [email protected]:/home/username/BAK/AndroidDev/
expect "password:"
send "thepassword\r"
interact
sleep 1
spawn rsync -vruEtl --progress -h --log-file=rsync.log --fuzzy --stats /home/james/Android/ [email protected]:/home/username/BAK/Android/
expect "password:"
send "thepassword\r"
interact
sleep 1
spawn rsync -vruEtl --progress -h --log-file=rsync.log --fuzzy --stats /home/james/Videos/ [email protected]:/home/username/BAK/Videos/ ;
expect "password:"
send "thepassword\r"
interact
sleep 1
spawn rsync -vruEtl --progress -h --log-file=rsync.log --fuzzy --stats /home/james/VirtualBox\ VMs/ [email protected]:/home/username/BAK/"VirtualBox\ VMs/" ;
expect "password:"
send "thepassword\r"
interact
sleep 1
spawn rsync -vruEtl --progress -h --log-file=rsync.log --fuzzy --stats /home/james/Pictures/ [email protected]:/home/username/BAK/Pictures ;
expect "password:"
send "thepassword\r"
interact
sleep 1
spawn scp -v /home/james/.vimrc u[email protected]:/home/username/BAK/ ;
expect "password:"
send "thepassword\r"
interact
sleep 1
spawn scp -v /home/james/.bashrc [email protected]:/home/username/BAK/ ;
expect "password:"
send "thepassword\r"
interact
sleep 1
spawn scp -v /home/james/.profile [email protected]:/home/username/BAK/ ;
expect "password:"
send "thepassword\r"
interact
sleep 1
spawn scp -v /home/james/.xsession* [email protected]:/home/username/BAK/ ;
expect "password:"
send "thepassword\r"
interact
sleep 1
如果我改变spawn rsync -vruEtl --progress -h --log-file=rsync.log --fuzzy --stats /home/rschostag/VirtualBox\ VMs/ [email protected]:/home/directory/BAK/VirtualBox
到spawn scp -vr /home/rschostag/VirtualBox\ VMs/ [email protected]:/home/directory/BAK/VirtualBox
,它的工作原理。但是,我不想每次都进行完整备份。
增量备份此目录或使rsync命令正常工作的最佳方式是什么?
谢谢!
按照要求,请找的expect -d script
输出如下:
$ sudo expect -d rsync_backup
expect version 5.45
argv[0] = expect argv[1] = -d argv[2] = rsync_backup
set argc 0
set argv0 "rsync_backup"
set argv ""
executing commands from command file rsync_backup
spawn rsync -vruEtl --progress -h --log-file=rsync.log --fuzzy --stats /home/james/Documents/ [email protected]:/home/username/BAK/Documents/
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {5064}
expect: does "" (spawn_id exp6) match glob pattern "password:"? no
[email protected] password:
expect: does "[email protected] password: " (spawn_id exp6) match glob pattern "password:"? yes
expect: set expect_out(0,string) "password:"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "[email protected] password:"
send: sending "thepassword\r" to { exp6 }
tty_raw_noecho: was raw = 0 echo = 1
spawn id exp6 sent <\r\n>
spawn id exp6 sent <sending incremental file list\r\n>
sending incremental file list
spawn id exp6 sent <Scripts/rsync.log\r\n>
Scripts/rsync.log
spawn id exp6 sent <\r 2.29K 0% 0.00kB/s 0:00:00 >
2.29K 0% 0.00kB/s 0:00:00 spawn id exp6 sent <\r 5.26M 100% 78.42MB/s 0:00:00 (xfr#1, ir-chk=1561/3024)\r\n>
5.26M 100% 78.42MB/s 0:00:00 (xfr#1, ir-chk=1561/3024)
spawn id exp6 sent <projects/JOBS/jobsearch_production/\r\n>
projects/JOBS/jobsearch_production/
spawn id exp6 sent <projects/JOBS/jobsearch_production/db.sqlite3\r\n>
projects/JOBS/jobsearch_production/db.sqlite3
spawn id exp6 sent <\r 5.41K 0% 0.00kB/s 0:00:00 >
5.41K 0% 0.00kB/s 0:00:00 spawn id exp6 sent <\r 7.35M 100% 73.71MB/s 0:00:00 (xfr#2, ir-chk=1025/6252)\r\n>
7.35M 100% 73.71MB/s 0:00:00 (xfr#2, ir-chk=1025/6252)
spawn id exp6 sent <\r\nNumber of files: 10,529 (reg: 8,419, dir: 2,096, link: 14)>
Number of files: 10,529 (reg: 8,419, dir: 2,096, link: 14)spawn id exp6 sent <\r\nNumber of created files: 0>
Number of created files: 0spawn id exp6 sent <\r\nNumber of regular files transferred: 2>
Number of regular files transferred: 2spawn id exp6 sent <\r\nTotal file size: 1.73G bytes>
Total file size: 1.73G bytesspawn id exp6 sent <\r\nTotal transferred file size: 12.61M bytes>
Total transferred file size: 12.61M bytesspawn id exp6 sent <\r\nLiteral data: 62.70K bytes>
Literal data: 62.70K bytesspawn id exp6 sent <\r\nMatched data: 12.55M bytes>
Matched data: 12.55M bytesspawn id exp6 sent <\r\nFile list size: 0>
File list size: 0spawn id exp6 sent <\r\nFile list generation time: 0.001 seconds>
File list generation time: 0.001 secondsspawn id exp6 sent <\r\nFile list transfer time: 0.000 seconds>
File list transfer time: 0.000 secondsspawn id exp6 sent <\r\nTotal bytes sent: 333.42K>
Total bytes sent: 333.42Kspawn id exp6 sent <\r\nTotal bytes received: 40.66K>
Total bytes received: 40.66Kspawn id exp6 sent <\r\n\r\n>
spawn id exp6 sent <sent 333.42K bytes received 40.66K bytes 32.53K bytes/sec\r\ntotal size is 1.73G speedup is 4,616.35>
sent 333.42K bytes received 40.66K bytes 32.53K bytes/sec
total size is 1.73G speedup is 4,616.35spawn id exp6 sent <\r\n>
interact: received eof from spawn_id exp6
tty_set: raw = 0, echo = 1
spawn rsync -vruEtl --progress -h --log-file=rsync.log --fuzzy --stats /home/james/AndroidDev/ [email protected]:/home/username/BAK/AndroidDev/
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {5069}
expect: does "" (spawn_id exp7) match glob pattern "password:"? no
[email protected] password:
expect: does "[email protected] password: " (spawn_id exp7) match glob pattern "password:"? yes
expect: set expect_out(0,string) "password:"
expect: set expect_out(spawn_id) "exp7"
expect: set expect_out(buffer) "[email protected] password:"
send: sending "thepassword\r" to { exp7 }
tty_raw_noecho: was raw = 0 echo = 1
spawn id exp7 sent <\r\n>
spawn id exp7 sent <sending incremental file list>
sending incremental file listspawn id exp7 sent <\r\n>
spawn id exp7 sent <\r\n>
spawn id exp7 sent <Number of files: 2,758 (reg: 2,273, dir: 485)>
Number of files: 2,758 (reg: 2,273, dir: 485)spawn id exp7 sent <\r\n>
spawn id exp7 sent <Number of created files: 0>
Number of created files: 0spawn id exp7 sent <\r\nNumber of regular files transferred: 0\r\nTotal file size: 1.00G bytes>
Number of regular files transferred: 0
Total file size: 1.00G bytesspawn id exp7 sent <\r\nTotal transferred file size: 0 bytes>
Total transferred file size: 0 bytesspawn id exp7 sent <\r\nLiteral data: 0 bytes\r\nMatched data: 0 bytes>
Literal data: 0 bytes
Matched data: 0 bytesspawn id exp7 sent <\r\nFile list size: 0\r\nFile list generation time: 0.001 seconds>
File list size: 0
File list generation time: 0.001 secondsspawn id exp7 sent <\r\nFile list transfer time: 0.000 seconds>
File list transfer time: 0.000 secondsspawn id exp7 sent <\r\nTotal bytes sent: 74.25K\r\n>
Total bytes sent: 74.25K
spawn id exp7 sent <Total bytes received: 2.43K\r\n\r\nsent 74.25K bytes received 2.43K bytes 30.67K bytes/sec>
Total bytes received: 2.43K
sent 74.25K bytes received 2.43K bytes 30.67K bytes/secspawn id exp7 sent <\r\ntotal size is 1.00G speedup is 13,102.55>
total size is 1.00G speedup is 13,102.55spawn id exp7 sent <\r\n>
interact: received eof from spawn_id exp7
tty_set: raw = 0, echo = 1
spawn rsync -vruEtl --progress -h --log-file=rsync.log --fuzzy --stats /home/james/Android/ [email protected]:/home/username/BAK/Android/
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {5074}
expect: does "" (spawn_id exp8) match glob pattern "password:"? no
[email protected] password:
expect: does "[email protected] password: " (spawn_id exp8) match glob pattern "password:"? yes
expect: set expect_out(0,string) "password:"
expect: set expect_out(spawn_id) "exp8"
expect: set expect_out(buffer) "[email protected] password:"
send: sending "thepassword\r" to { exp8 }
tty_raw_noecho: was raw = 0 echo = 1
spawn id exp8 sent <\r\n>
spawn id exp8 sent <sending incremental file list\r\n>
sending incremental file list
spawn id exp8 sent <\r\nNumber of files: 3 (dir: 3)>
Number of files: 3 (dir: 3)spawn id exp8 sent <\r\n>
spawn id exp8 sent <Number of created files: 0>
Number of created files: 0spawn id exp8 sent <\r\nNumber of regular files transferred: 0>
Number of regular files transferred: 0spawn id exp8 sent <\r\nTotal file size: 0 bytes>
Total file size: 0 bytesspawn id exp8 sent <\r\nTotal transferred file size: 0 bytes>
Total transferred file size: 0 bytesspawn id exp8 sent <\r\n>
spawn id exp8 sent <Literal data: 0 bytes\r\nMatched data: 0 bytes\r\nFile list size: 0>
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 0spawn id exp8 sent <\r\n>
spawn id exp8 sent <File list generation time: 0.001 seconds\r\nFile list transfer time: 0.000 seconds\r\nTotal bytes sent: 83>
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 83spawn id exp8 sent <\r\nTotal bytes received: 21>
Total bytes received: 21spawn id exp8 sent <\r\n\r\n>
spawn id exp8 sent <sent 83 bytes received 21 bytes 69.33 bytes/sec\r\ntotal size is 0 speedup is 0.00>
sent 83 bytes received 21 bytes 69.33 bytes/sec
total size is 0 speedup is 0.00spawn id exp8 sent <\r\n>
interact: received eof from spawn_id exp8
tty_set: raw = 0, echo = 1
spawn rsync -vruEtl --progress -h --log-file=rsync.log --fuzzy --stats /home/james/Videos/ [email protected]:/home/username/BAK/Videos/
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {5079}
expect: does "" (spawn_id exp9) match glob pattern "password:"? no
[email protected] password:
expect: does "[email protected] password: " (spawn_id exp9) match glob pattern "password:"? yes
expect: set expect_out(0,string) "password:"
expect: set expect_out(spawn_id) "exp9"
expect: set expect_out(buffer) "[email protected] password:"
send: sending "thepassword\r" to { exp9 }
tty_raw_noecho: was raw = 0 echo = 1
spawn id exp9 sent <\r\n>
spawn id exp9 sent <sending incremental file list\r\n>
sending incremental file list
spawn id exp9 sent <\r\nNumber of files: 30 (reg: 29, dir: 1)\r\nNumber of created files: 0>
Number of files: 30 (reg: 29, dir: 1)
Number of created files: 0spawn id exp9 sent <\r\nNumber of regular files transferred: 0>
Number of regular files transferred: 0spawn id exp9 sent <\r\nTotal file size: 1.35G bytes>
Total file size: 1.35G bytesspawn id exp9 sent <\r\nTotal transferred file size: 0 bytes>
Total transferred file size: 0 bytesspawn id exp9 sent <\r\nLiteral data: 0 bytes>
Literal data: 0 bytesspawn id exp9 sent <\r\nMatched data: 0 bytes\r\nFile list size: 0>
Matched data: 0 bytes
File list size: 0spawn id exp9 sent <\r\nFile list generation time: 0.001 seconds>
File list generation time: 0.001 secondsspawn id exp9 sent <\r\nFile list transfer time: 0.000 seconds>
File list transfer time: 0.000 secondsspawn id exp9 sent <\r\nTotal bytes sent: 587\r\n>
Total bytes sent: 587
spawn id exp9 sent <Total bytes received: 11\r\n\r\nsent 587 bytes received 11 bytes 398.67 bytes/sec\r\n>
Total bytes received: 11
sent 587 bytes received 11 bytes 398.67 bytes/sec
spawn id exp9 sent <total size is 1.35G speedup is 2,263,533.89\r\n>
total size is 1.35G speedup is 2,263,533.89
interact: received eof from spawn_id exp9
tty_set: raw = 0, echo = 1
spawn rsync -vruEtl --progress -h --log-file=rsync.log --fuzzy --stats /home/james/VirtualBox VMs/ [email protected]:/home/username/BAK/"VirtualBox VMs/"
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {5084}
expect: does "" (spawn_id exp10) match glob pattern "password:"? no
[email protected] password:
expect: does "[email protected] password: " (spawn_id exp10) match glob pattern "password:"? yes
expect: set expect_out(0,string) "password:"
expect: set expect_out(spawn_id) "exp10"
expect: set expect_out(buffer) "[email protected] password:"
send: sending "thepassword\r" to { exp10 }
tty_raw_noecho: was raw = 0 echo = 1
spawn id exp10 sent <\r\n>
spawn id exp10 sent <sending incremental file list\r\n>
sending incremental file list
这是它挂起,并且不提供,我可以识别的错误消息。
我移动了远程的VirtualBox目录并重新启动了备份,并在运行备份几天后最终完成。备份的总大小为71 GB。我用expect -d
运行它,它在终端中输出一个非常详细的输出,所以这是有帮助的,因为没有-d的脚本可能看起来像挂了,因为它没有在输出中打印任何东西。所以,我相信,除了没有任何进展迹象之外,没有任何错误,这让我相信它可能没有用。
谢谢你给我提供关于expect -d
选项的建议。
使用'指望eof',而不是'interact'。此外,添加调试输出,以便您可以看到期望停止的位置:'expect -d your_script.exp' –
我运行'expect -d'并发现期望不理解'$ USER',并且现在我意识到期望不会理解许多内置的bash变量,例如$ USER。所以,我用用户名目录替换了它,并且它正在运行。输出将被保存到一个日志文件中,并且我将用该输出更新我的问题。谢谢! – Debug255
期望您可以参考这样的环境变量:'$ env(USER)'。确保在shell的一面,输出你希望可用的变量。 –