Cron job runs but has no effect

CypherBYTE

Verified User
Joined
May 20, 2020
Messages
10
I am trying to set up an automatic backup for a MySQL database. CentOS 7.

I have a command I can run in SSH that works fine:

Code:
sudo mysqldump -u MySQLUser -pPASSWORD dbname | gzip > Admin/ers_`date '+%Y%m%d-%H%M'`.sql.gz

I have setup a cron job and it appears to be executed in the cron logs, with no indication of errors, BUT it does appear to be truncated:

Code:
May 26 03:39:40 vps crontab[31363]: (root) LIST (admin)
May 26 03:40:01 vps CROND[31388]: (admin) CMD (sudo mysqldump -u admin_ers -pPASSWORD admin_ers | gzip > Admin/ers_`date '+)
May 26 03:40:01 vps CROND[31390]: (root) CMD (/usr/local/directadmin/dataskq)
May 26 03:40:20 vps crontab[31394]: (root) LIST (admin)
May 26 03:41:01 vps CROND[417]: (root) CMD (/usr/local/directadmin/dataskq)
May 26 03:42:01 vps CROND[474]: (root) CMD (/usr/local/directadmin/dataskq)

Yet, still nothing happens.

I have tried giving full rwx rights (777) to the Admin folder, adding the admin user to the wheel group, even tried un-remming this line in the sudoers file:

Code:
%wheel    ALL=(ALL)      NOPASSWD: ALL

Any ideas what I might be missing?
 
Thanks, but I'd really like to be able to specify which database to backup. I also want to find out why it isn't working now ... for the sake of sanity!
 
in such case - try to use da_admin or root (mysql) credentials to backup databases, or you want to use for each database it's own credentials?
 
Ok, I will reconfigure it to use the root user. I was trying to avoid that.

I really don't understand why the cron won't run the command but I can run the command directly. Might it have something to do with the way the logs seem to have truncated the command?
 
You may put command to bash script and run it with cron, also try to add user before command, like:
1 5 * * * root mysqldump -u MySQLUser -pPASSWORD dbname | gzip > Admin/ers_`date '+%Y%m%d-%H%M'`.sql.gz
 
Why do you have sudo in the command? And you may need to have the full path to mysqldump in the command.
 
You may put command to bash script and run it with cron
This got it running as desired. As soon as I put the command in a bash script, it started working. Thank you!

Why do you have sudo in the command?
The sudo is there because I am VERY new to VPS and UNIX and it's part of the trials / attempts I made to try to get the cron to run.

And you may need to have the full path to mysqldump in the command.
Thankfully I didn't because I wouldn't know where it is! :ROFLMAO:
 
Back
Top