在后台运行 rsync

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6141710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 00:57:35  来源:igfitidea点击:

Running rsync in background

linuxbackgroundrsync

提问by Mirage

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

现在这是否意味着我的进程仍在运行它已停止

采纳答案by Nemo

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 重定向 stdin 来消除错误:

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.

...但是它可能会失败,因为它无法读取它试图读取的任何内容。

回答by Hyperboreus

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.

所以是的,你的输出看起来你的进程没有运行。

Check ps to see if rsync is running.

检查 ps 以查看 rsync 是否正在运行。

回答by KARASZI István

No, it means it has been stopped.

不,这意味着它已被停止。

You can check it with jobs.

您可以使用jobs.

Example output:

示例输出:

jobs
[1]+  Stopped                 yes

Then you can reactivate with fg, example:

然后你可以重新激活fg,例如:

fg 1

回答by niofox

When you press "ctrl + z" then the process stopped and go to background.

当您按“ctrl + z”时,该过程停止并转到后台。

[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

按“jobs”查看进程正在运行

[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

如果你想进入前台,请按“fg 1” 1 是进程号

回答by Michael

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 . & 

回答by sayantan chakraborty

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

使命令生效

回答by Jinna Balu

The solution to keep rsync running in background

保持rsync在后台运行的解决方案

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

Nohupallows to run a process/command or shell script to continue working in the background even if you close the terminal session.

即使您关闭终端会话,Nohup 也允许运行进程/命令或 shell 脚本以继续在后台工作。

In our example, we also added ‘&' at the end, that helps to send the process to background.

在我们的示例中,我们还在末尾添加了“&”,这有助于将进程发送到后台。

Output example:

输出示例:

 nohup rsync -avp [email protected]:/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

同步状态

cat nohup.out