简体   繁体   English

在后台运行 rsync

[英]Running rsync in background

I use this to run rsync in background我用它在后台运行 rsync

rsync -avh /home/abc/abac /backups/ddd &

When i do that i see line saying 1 process stopped.当我这样做时,我看到一行说 1 个进程已停止。

Now does that mean my process is still running ot it is stopped现在这是否意味着我的进程仍在运行,但它已停止

When you press "ctrl + z" then the process stopped and go to background.当您按“ctrl + z”时,进程停止,go 进入后台。

[1]+ Stopped rsync -ar --partial /home/webup/ /mnt/backup/ [1]+ 停止 rsync -ar --partial /home/webup/ /mnt/backup/

Now press "bg" and will start in background the previous process you stopped.现在按“bg”,将在后台启动您停止的上一个进程。

[1]+ rsync -ar --partial /home/webup/ /mnt/backup/ & [1]+ rsync -ar --partial /home/webup/ /mnt/backup/ &

Press "jobs" to see the process is running按“作业”查看进程正在运行

[1]+ Running rsync -ar --partial /home/webup/ /mnt/backup/ & [1]+ 运行 rsync -ar --partial /home/webup/ /mnt/backup/ &

If you want to to go in foreground press "fg 1" 1 is the process number如果你想 go 在前台按“fg 1” 1 是进程号

It is probably trying to read from the terminal (to ask you for a password, perhaps).它可能正在尝试从终端读取(也许是要求您输入密码)。 When a background process tries to read from the terminal, it gets stopped.当后台进程尝试从终端读取时,它会停止。

You can make the error go away by redirecting stdin from /dev/null:您可以通过从 /dev/null 重定向标准输入来消除错误 go:

rsync -avh /home/abc/abac /backups/ddd < /dev/null &

...but then it will probably fail because it will not be able to read whatever it was trying to read. ...但是它可能会失败,因为它将无法读取它试图读取的任何内容。

The solution to keep rsync running in background保持rsync在后台运行的解决方案

nohup rsync -a host.origin:/path/data destiny.host:/path/ &

Nohup allows to run a process/command or shell script to continue working in the background even if you close the terminal session. Nohup允许运行进程/命令或 shell 脚本以继续在后台工作,即使您关闭终端 session 也是如此。

In our example, we also added '&' at the end, that helps to send the process to background.在我们的示例中,我们还在末尾添加了“&”,这有助于将进程发送到后台。

Output example: Output 示例:

 nohup rsync -avp root@61.0.172.109:/root/backup/uploads/ . &

 [1] 33376
 nohup: ignoring input and appending output to 'nohup.out'

That's all, now your rsync process will run in the background, no matter what happens it will be there unless you kill the process from command line, but it will not be interrupted if you close your linux terminal, or if you logout from the server.就是这样,现在您的 rsync 进程将在后台运行,无论发生什么,除非您从命令行终止该进程,否则它将在那里,但如果您关闭 linux 终端,或者如果您从服务器注销,它不会被中断.

RSync Status RSync 状态

cat nohup.out

No, it means it has been stopped.不,这意味着它已经停止了。

You can check it with jobs .您可以使用jobs检查它。

Example output:示例 output:

jobs
[1]+  Stopped                 yes

Then you can reactivate with fg , example:然后您可以使用fg重新激活,例如:

fg 1

This is safe, you can monitor nohup.out to see the progress.这是安全的,您可以监视 nohup.out 以查看进度。

nohup rsync -avrt --exclude 'i386*' --exclude 'debug' rsync://mirrors.kernel.org/centos/6/os . & 

File Transfer:文件传输:

nohup scp oracle@<your_ip>:/backup_location/backup/file.txt . > nohup.out 2>&1 &

then hit ctrl-z然后按 ctrl-z

$ bg

To bring the command alive使命令活跃起来

If everything works, your call should return you the PID of the new progress and some time later a "Done" message.如果一切正常,您的呼叫应返回新进度的 PID,并在一段时间后返回“完成”消息。

So yeah, your output looks like your process is not running.所以是的,你的 output 看起来你的进程没有运行。

Check ps to see if rsync is running.检查 ps 以查看 rsync 是否正在运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM