Solved

Mysqldump backup script and crontab error

Posted on 2014-01-10
3
689 Views
Last Modified: 2014-01-15
Hi,

I've got the following mysqldumb backup scritpt:

#/bin/sh
mysqldump -u username -pmypass --all-databases > DB.sql
gzip DB.sql
NOW=$(date +"mysql-backup-%H%M-%d-%m-%y")
mv DB.sql.gz /home/user/BACKUPS/"$NOW.gz"

It works fine when I start it manually. When i put it in crontab, I get the following error:

mysqldump: Couldn't execute 'SHOW TRIGGERS LIKE 'data\_29'': Got error 28 from storage engine (1030)

I reasearched that error 28 means there is not enough storage. That was the case but i free up some space and I'm still getting this error. Also under crontab the backup file is nearly half the size.
0
Comment
Question by:jackal077
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Accepted Solution

by:
Red-King earned 500 total points
ID: 39771644
Which user's crontab are you using to run the script, root or your own user?

I noticed you are missing the '!' from the first line of your script, it should be #!/bin/sh

If  you are running the script using root's crontab the working directory will be the root users home directory i.e. /root
The DB.sql file will be created in the /root directory so you will need to be sure that you have enough space there to save the dump file.

If you want to change the working directory you can simply add a line to change the directory at the start of the script i.e.

#!/bin/sh
NOW=$(date +"mysql-backup-%H%M-%d-%m-%y")

cd /home/user/BACKUPS
mysqldump -u username -pmypass --all-databases > DB.sql
gzip DB.sql
mv DB.sql.gz ./"$NOW.gz"

Open in new window


I imagine that the backup is half the size as it is not completing.
I expect you can tell gzip to output with a specific filename to cut out the extra mv command.
I think the tar command would be (double check the syntax as this is off the top of my head);

tar -czf ./"$NOW.tar.gz" DB.sql
0
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 39773426
Hi!

To take a backup and compress the file in one line of code do this
#!/bin/sh
backfile=$(date +"mysql-backup-%H%M-%d-%m-%y")
myuser=yourusername
mypass=yourpassw
cd /home/user/BACKUPS
mysqldump -u $myuser -p$mypass --all-databases | gzip -9 > $backfile.sql.gz

Open in new window


This will compress your backup as much as possible on the fly and save storage.

Regards,
      Tomas Helgi
0
 

Author Comment

by:jackal077
ID: 39781959
Hi,
yes, I must have missed the !. Cron runs under root. I didn't realize I had to define the path inside the script. That was it. Thx.
0

Featured Post

Upcoming Webinar: Securing your MySQL/MariaDB data

Join Percona’s Chief Evangelist, Colin Charles as he presents Securing your MySQL®/MariaDB® data on Tuesday, July 11, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Creating and Managing Databases with phpMyAdmin in cPanel.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question