I am having problems with getting a crontab
to work. I want to automate a MySQL database backup.
The setup:
- Debian GNU/Linux 7.3 (wheezy)
- MySQL Server version: 5.5.33-0+wheezy1(Debian)
- directories user, backup and backup2 have 755 permission
- The user names for MySQL db and Debian account are the same
From the shell this command works
mysqldump -u user -p[user_password] [database_name] | gzip > dumpfilename.sql.gz
When I place this in a crontab using crontab -e
* * /usr/bin/mysqldump -u user -pupasswd mydatabase | gzip> /home/user/backup/mydatabase-backup-`date +\%m\%d_\%Y`.sql.gz >/dev/null 2>&1
A file is created every minute in /home/user/backup directory, but has 0 bytes.
However when I redirect this output to a second directory, backup2, I note that the proper mysqldumpfile duly compressed is created in it. I am unable to figure what is the mistake that I am making that results in a 0 byte file in the first directory and the expected output in the second directory.
* * /usr/bin/mysqldump -u user -pupasswd my-database | gzip> /home/user/backup/mydatabase-backup-`date +\%m\%d_\%Y`.sql.gz >/home/user/backup2/mydatabase-backup-`date +\%m\%d_\%Y`.sql.gz 2>&1
I would greatly appreciate an explanation.
Thanks