linux - Pause a shell script every x (mili)seconds to decrease immediate CPU usage -


I have a shell script that backs up my MySQL database every hour. This is a basic script:

  mysqldump --user = $ USER --password = $ PASS $ DB> / $ PATH / $ DATE.sql & amp; Amp; 7z A-7z -MX = 9/1/1 PATH / DADT SCL.7 / 002 PATH / DADTS SCL & amp; Rm / $ PATH / $ DATE.sql  

I am using compressed compression because:

  • File permissions and owner / group not required
  • The space saved by 7z is more important to me than the jiz

The one thing that can disturb me is that 7z 2) It takes about 30 seconds during that time and uses a lot CPU on my server weight graph, it gets 50% injury and I get rid of those peaks Expertise have.

I am already implementing this script with nice :

  0 * * * * / usr / bin / nice - N 19 / path / to / backup.sh> / Dev / null  

At this point, I can do the only solution, in some way to stop the execution of the 7z part, we say that every second Second for 1. It can free up CPU time for other processes.

Is this possible?

I am doing something like this in my .php script, although the breaks are in the loop, for example:

  while ($ d) = Mysqli_fetch_assoc ($ q)) {sleep (250000); // process $ d}  

I want to execute 7z for every x (some) sleep for 1 second.

You can use

  prlimit - cpu = 10 7z A -t7z -mx = 9 / $ pat / $ DATE.sql.7z /$PATH/$DATE.sql  

CPU will limit usage to 10%

< / Div>

Comments