Solved

Mysqldump backup script and crontab error

Posted on 2014-01-10
3
665 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
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 24

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now