0

I have a script with a mysqldump command that looks like this:

 mysqldump ${mysql_auth_args} \
        --force \
        --single-transaction \
        --quick \
        --compact \
        --extended-insert \
        --order-by-primary

I'm seeing the strangest behavior, and only on one machine: when I run the script directly, it works as expected. When it runs from cron though, the resulting file only has CREATE statements and no INSERTS

I've used this command to try to simulate the environment it runs in under cron and the output does contain data:

env -i "$(cat /etc/crontab | grep -v '#' | grep -v '^$' | grep -v /etc/cron)" /etc/cron.daily/restic-backup

On other seemingly identical VMs, this issue doesn't happen. Admittedly, this system is pretty dated:

$ mysqldump --version
mysqldump  Ver 10.13 Distrib 5.5.58, for debian-linux-gnu (x86_64)

What factors could possibly be causing mysqldump to behave as if --no-data were passed, but only when run by cron?

3
  • On my system, /etc/crontab isn't even readable for mere users so I don't know what that was about (apart from winning a UUOC award ;)), but if restic-backup is a shell script, maybe add a set -x and some logging to it to debug what it's really doing?
    – ckujau
    Apr 22 '21 at 16:38
  • That little incantation is to be run from under root, I picked it up somewhere on the interwebs a while back as a way to approximate the env cron runs things under. restic-backup is a shell script that doesn't appear to be producing any errors. mysqldump works and generates schema in the cases it's missing data Apr 22 '21 at 18:00
  • can you remove new lines from script of backup & write whole command without any new lines or break, only space should use for separator Apr 23 '21 at 11:16

Your Answer

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

Browse other questions tagged or ask your own question.