Kah*_*ahn 3 cron rsync cpulimit
我打电话cpulimit
的cron
:
00 16 * * * /usr/bin/cpulimit --limit 20 /bin/sh /media/storage/sqlbackup/backups.sh
当作业开始时,CPU 会像往常一样出现峰值和警报,没有发生实际可识别的限制。作业本身遍历许多子目录的目录并rsync
每次执行's ,我相信这会产生rsync
子进程(运行 top 将有一个可用于被调用的 rsync 的 pid,几分钟后它将有一个不同的 pid for rsync
)。
我不确定如何正确利用cpulimit
以有效限制此过程消耗的使用量。
记住这是一个具有 2G RAM 和 1vCPU 的 VM 可能很重要。
默认情况下cpulimit
不限制子进程,因此rsync
根本不受限制。如果您运行的是足够新的版本,cpulimit
您应该能够使用--include-children
(或-i
) 选项。(另请参阅此答案。)
$ cpulimit -h
Usage: cpulimit [OPTIONS...] TARGET
OPTIONS
-l, --limit=N percentage of cpu allowed from 0 to 400 (required)
-v, --verbose show control statistics
-z, --lazy exit if there is no target process, or if it dies
-i, --include-children limit also the children processes
-h, --help display this help and exit
TARGET must be exactly one of these:
-p, --pid=N pid of the process (implies -z)
-e, --exe=FILE name of the executable program file or path name
COMMAND [ARGS] run this command and limit it (implies -z)
Report bugs to <marlonx80@hotmail.com>.
Run Code Online (Sandbox Code Playgroud)
这会将您的 cron 条目更改为:
00 16 * * * /usr/bin/cpulimit --include-children --limit 20 /bin/sh /media/storage/sqlbackup/backups.sh
编辑:当 OP 回答(他们自己)时,它将对脚本中cpulimit
的rsync
命令起作用,但这并不能确保您的脚本在执行其他功能时运行良好。例如,如果脚本必须处理大量目录,它可能会使系统陷入困境并导致 CPU 峰值和警报。