tar.gz backup script for mysql directory times out if run from cron
Hello everyone,
I’m having trouble with a mysql directory backup script timing out when started by cron. I can run the script from command line and it completes successfully, but when cron starts it, it ends long before the backup is complete. I have several servers running the same script successfully from cron. The directory I’m attempting to backup is 103GB, the successful tar.gz files have been 15GB. The tar.gz files I get from cron are ~600MB and are corrupt. When I ran the script from command line, I watched the resource use and there is a fairly steady ~90% CPU use, physical memory use is ~1.1GB, and virtual memory use is ~14GB. This is a RHEL 5.3 server running on VMware. Here is the first part of the script: ___________________________________________________________ Code:
#!/bin/sh After this I set some FTP variables and send the backup to the FTP server. It is making it there, but the small, corrupt backup is useless. I have also looked to see if there is a timeout associated with cron or background jobs and/or related configurations, again without luck. I apologize if this has been covered, I did search here and Google without any promising results. Any help is greatly appreciated. Thanks |
Your CRON should complete successfully although it might have other issues,
like - is it maybe set to run too often, like perhaps every 2 hours and in that time the first doesn't finish while the second already starts ? You should use [CODE] tags around the scripts to preserve formatting, like: Code:
#!/bin/sh Code:
tar -czvf /backups/dirname.servername.tar.gz . The second issue is FTP transfer - what command do you execute to transfer file ? I'm used to "LFTP", to make SURE that file is transferred correctly. If you post your complete script you're using, someone could even give you more solution. good luck |
I'm actually running this script once daily. I know there are a few places I could make it more efficient (such as putting the FTP credentials before the loop), but this was developed in a hurry with a lot of Google assistance (I know I'm no hardcore script developer). I don't have any trouble from the FTP section, but I'm happy to share the code if it helps my problem or helps bail anyone else out. I'm hesitant to change the backup from “.” to “*” only because I know this works from command line testing and on the other servers I have this running on. I did re-edit my original post adding CODE and /CODE, thanks for that (I’m a newbie here and appreciate the feedback.
I also just changed the crontab entry to send output and errors to a log. If this helps resolve the issue, I’ll be sure to update the thread with the answer. The full (now generic) script is below: Code:
#!/bin/sh |
Quote:
tar -czvf /backups/dirname.servername.tar.gz * does not glob . files. |
Hi,
your script really doesn't do anything weird, but this is how I would do it (my backup script with TAR) - check the TAR you're using Code:
tar --version - get rid (delete) of LOOP and so much comment hashes ### Code:
for PRACTICE in {practice name was here} - rewrite the code for TAR Code:
# Backup the practice databases Then I would run the script manually first and see if it works and then add it to CRON to "test". I didn't see that CRON would not do the job/end it before finished, since it happened that my FTP server was down for few days and all the jobs were waiting 3 days to FTP transfer all the backups made. good luck and good night for now (since it's afternoon at you and almost midnight where I am) |
I expected adding logging to the crontab entry would help me troubleshoot the issue. I didn’t expect it to actually resolve the issue which appears to be the case. I logged in last night expecting to have a log, a failed tar.gz, and the need to run it manually (which always worked). I was surprised to find a 7+GB tar.gz file (it typically died around 600MB) that was still growing. There was also nothing in the log to indicate any type of problem at all (too bad, I would have liked to know what had been happening and have a solid feeling that it was resolved and how). Regardless, the only change was made to the crontab entry.
The original entry: Code:
30 21 * * * /backups/mumoves/mysql_tar_backup.sh Code:
30 21 * * * /backups/mumoves/mysql_tar_backup.sh 2>&1 >/backups/mumoves/mysql_tar_backup.log |
Code:
30 21 * * * /backups/mumoves/mysql_tar_backup.sh and it's always nice to see that something is solved :-) |
Actually, the cron log only showed the start times of cron entries and wasn't that big. Whatever the reason, I'm happy its resolved and thankful for all the helpfull suggestions.
|
All times are GMT -5. The time now is 08:42 PM. |