1

I have a script that creates a backup of my database. When I am executing the script manually, the backup is successfully created. But when I am using a cronjob to execute the script, the backupfile is created, but it is completely empty.

#!/bin/sh
#----------------------------------------------------
# a simple mysql database backup script.
# version 1 - 14.11.2014
#----------------------------------------------------
# (1) set up all the mysqldump variables
FILE=backuprelease.sql.`date +"%Y%m%d %T"`
DBSERVER=127.0.0.1
DATABASE=myschema
USER=admin
PASS=adminpassword
# (2) in case you run this more than once a day, remove the previous version of the file
unalias rm     2> /dev/null
rm ${FILE}     2> /dev/null
rm ${FILE}.gz  2> /dev/null
# (3) do the mysql database backup (dump)
# use this command for a database server on a separate host:
#mysqldump --opt --protocol=TCP --user=${USER} --password=${PASS} --host=${DBSERVER} ${DATABASE} > ${FILE}
# use this command for a database server on localhost. add other options if need be.
cd /etc/mysql/backup/backups
mysqldump --opt --user=${USER} --password=${PASS} ${DATABASE} > ${FILE}
# (4) gzip the mysql database dump file
#gzip $FILE
# (5) show the user the result
echo "${FILE}.gz was created:"
#ls -l ${FILE}.gz

My cronjob looks like this:

0 */12   * * *   root   cd /etc/mysql/backup/ && sh backupReleaseShell.sh

And my permissions for the directories are the following:

-rwxr-xr-x 1 root root      1057 Sep 28 12:17 backupReleaseShell.sh
drwxr-xr-x 2 root root      4096 Sep 28 12:58 backups

I have no idea what the problem is right now. I would be very grateful, if anyone could help me with that issue.

Thank you in advance!

John

John
  • 111
  • 5
  • Possible duplicate of [PHP regular backup of mysql data](http://stackoverflow.com/questions/38916163/php-regular-backup-of-mysql-data) – e4c5 Sep 28 '16 at 14:32
  • That does not solve my problem. But thank you – John Sep 30 '16 at 08:37

0 Answers0