Solved

Mysqldump backup script and crontab error

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Does PHPMyAdmin pose a security risk? 2 93
count download link and run update query 9 55
PHP - AJAX and MySQL it works only if the value is a number 12 36
sql_mode 1 18
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

911 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

21 Experts available now in Live!

Get 1:1 Help Now