12

I have set up a backup script to back up world data on my Minecraft server hourly using cron, but because the worlds being constantly edited by players, tar was telling me that files changed while they were read. I added --ignore-command-error to the tar in the script and that suppresses any errors when I run it manually, however cron still sends a mail message saying that files were changed while being read, and ends up flooding my mail because it's run once an hour. Anyone know how to fix this? This is the script:

filename=$(date +%Y-%m-%d)
cd /home/minecraft/Server/
for world in survival survival_nether survival_the_end creative superflat
do
if [ ! -d "/home/minecraft/backups/$world" ]; then
mkdir /home/minecraft/backups/$world
fi
find /home/minecraft/backups/$world -mtime +1 -delete
tar --ignore-command-error -c $world/ | nice -n 10 pigz -9 > /home/minecraft/backups/$world/$filename.tar.gz
done
20

Cron will attempt to send an email with any output that may have occurred when the command was run. From cron's man page:

When executing commands, any output is mailed to the owner of the crontab (or to the user specified in the MAILTO environment variable in the crontab, if such exists). Any job output can also be sent to syslog by using the -s option.

So to disable it for a specific crontab entry just capture all of the commands output and either direct it to a file or to /dev/null.

30 * * * * notBraiamsBackup.sh >/dev/null 2>&1
  • D: using my example! – Braiam Jul 25 '13 at 1:07
  • @Braiam - sorry I was feeling lazy and didn't feel like typing it up. I would've typed the same thing anyway 8-). – slm Jul 25 '13 at 1:12
  • @Braiam - is that better? 8-). – slm Jul 25 '13 at 1:14
  • Works great, exactly what I was looking for. – Carter Jul 25 '13 at 6:33
  • Note that in my CentOS 7, with crontab not cron, -s means selinux context..... – WesternGun Jan 9 '18 at 17:18
12

Instead of piping everything to /dev/null (which may leave you without a clue of what happened if something goes wrong), you can pipe your scripts to log files like this:

30 * * * * backup.sh > ~/logs/backup.log

And to stop getting mails, just set the MAILTO variable to an empty string at the beginning of your crontab file:

MAILTO=""
4

If you don't want mails for an specific cron task, you can simply add >/dev/null 2>&1 at the end of the line:

30 * * * * backup.sh >/dev/null 2>&1
  • I choose this way: you lost track of everything, but neatly. – WesternGun Jan 9 '18 at 17:09
0

You should add the following to your gnu tar command: --warning=no-file-changed

That will suppress all the "%s: file changed as we read it" messages. And by using this solution (and not redirecting everything to /dev/null), you will still be able to get error messages when stuff really goes wrong..


With the --warning flag you can enable and disable a lot of different messages that tar prints. Here's the relevant part of the manual with all the keywords you can use: https://www.gnu.org/software/tar/manual/html_section/tar_27.html.

Note: by adding "no-" in front of a keyword, the message will be suppressed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.