Question

I am trying to take back up in my cpanel using cron jobs.

My script is like this

/usr/bin/mysqldump --user=username --password=password --host=localhost dbname | gzip > /home/username/backups/dbbackup_$date.sql.gz

and in backup.sh

#!/bin/bash
date=`date +%Y%m%d_%k%M`;
  /usr/bin/mysqldump --user=username --password=password --host=localhost dbname | gzip > /home/username/backups/dbbackup_$date.sql.gz

and i have set the time for every 5 mins. But its not happening. Please suggest me where i am doing wrong

Was it helpful?

Solution

can you give the exact line of cron job? I tried this:

date=`date +%Y%m%d_%k%M`    
mysqldump -uroot -p12345 -h127.0.0.1 db | gzip > /home/ubuntu/root/db_$date.sql.gz

and it worked for me, may be there is some problem with your cron!!
To run every 5 minutes this is the syntax:

*/5 * * * * sh /home/ubuntu/root/backUpScript.sh

OTHER TIPS

Maybe you forget to chmod 777 on file backUpScript.sh, cronjob and folder dump database?

You may need to add some apostrophe to your code for example

/usr/bin/mysqldump --user=username --password=password --host=localhost dbname | gzip > /home/username/backups/dbbackup_$date.sql.gz

should be

/usr/bin/mysqldump --user='username' --password='password' --host='localhost' dbname | gzip > /home/username/backups/dbbackup_$date.sql.gz

This solved my issue. It does not give the ambiguous redirect error.

Put date as "$(date)"

mysqldump -uuser -ppassword -h127.0.0.1 db | gzip > /home/user/directory/db_"$(date)".sql.gz
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top