0
I’m trying to run a file .sh
to perform a backup of my database, but for some reason the cron to run this file is not working.
I’ve tried to make a lot of changes, but nothing works. All other cron work normally except this one should run my DB backup file.
Note: The file works and generates a backup of DB normally when running on the command line.
Just follow my code:
#!/bin/bash
# mobcliDB_bkp.sh
DATA=$(date '+%d-%m-Y-%T')
NOME="/root/data/mobcliDB_bkp-$DATA.sql"
HOST="localhost"
USER="root"
PASSWORD="*******"
DATABASE="mobcliDB"
/usr/bin/mysqldump -h $HOST -u $USER -p$PASSWORD $DATABASE > $NOME
zip -r /root/data/mobcliDB_bkp-$DATA.zip $NOME
rm /root/data/mobcliDB_bkp-$DATA.sql
The cron is like this:
*/5 * * * * /meu diretorio/mobcliDB_bkp.sh
I have other cron in the same file that work normally.
If you turn the remote manually, it works?
– Gabriel Santos
@Gabrielsantos Running manually works normal!
– Maiko Souza
is to run every 5 minutes?
– Gabriel Santos
@Gabrielsantos When it works, I will put to run 1 time a day, but for now I left every 5 minutes to test and see if it is working.
– Maiko Souza
Can be the zip that is not being recognized. Try to put the absolute path to it.
– Incrivel Monstro Verde Cabelud
It’s probably a permission issue. Is the script accessible and executable to the user you’re enabling crontab on? Check the cron logs in /var/log/cron and see what might be wrong.
– cemdorst