Solved

Mysqldump backup script and crontab error

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MySQL - Restore Database SQL File 5 54
mcrypt_create_iv() is deprecated 4 159
configure dependency in POM for new database 3 25
Complex MySQL Query 2 18
Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

772 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