Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've been running the following Bash script to do hourly backups of our MySQL databases. It was running for awhile, but lately our server has been having issues, and it appears as though it may be this script. Can anyone spot anything possibly wrong? I am by no means an expert Bash programmer, but this seems simple enough that I'm having a hard time figuring out what might be wrong. Any help would be much appreciated.
Code:
#!/bin/sh
# Drupal database backup
# ---------------------------------------------------------------------
#########################
######TO BE MODIFIED#####
### System Setup ###
BACKUP=/home/XXX/XXX
### MySQL Setup ###
MUSER="XXX"
MPASS="XXX"
MHOST="localhost"
### FTP server Setup ###
FTPD="./XXX"
FTPU="XXX"
FTPP="XXX"
FTPS="XXX"
######DO NOT MAKE MODIFICATION BELOW#####
#########################################
### Binaries ###
TAR="$(which tar)"
GZIP="$(which gzip)"
FTP="$(which ftp)"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
### Today + hour in 24h format ###
NOW=$(date +"%a%H")
### Create hourly dir ###
mkdir $BACKUP/$NOW
### Create dir for each databases, backup tables in individual files ###
mkdir $BACKUP/$NOW/XXX
FILE=$BACKUP/$NOW/XXX/XXX.sql.gz
$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS XXX | $GZIP -9 > $FILE
mkdir $BACKUP/$NOW/XXX
FILE=$BACKUP/$NOW/XXX/XXX.sql.gz
$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS XXX | $GZIP -9 > $FILE
### Compress all tables in one nice file to upload ###
cd $BACKUP
ARCHIVE=$BACKUP/$NOW.tar.gz
ARCHIVED=$BACKUP/$NOW
$TAR -cvf $ARCHIVE $ARCHIVED
### Dump backup using FTP ###
DUMPFILE=$NOW.tar.gz
$FTP -in $FTPS <<END_SCRIPT
quote USER $FTPU
quote PASS $FTPP
cd $FTPD
put $DUMPFILE
quit
END_SCRIPT
### Delete the backup dir and keep archive ###
rm -rf $ARCHIVED
### Clean up the databases ###
echo "Making things pretty"
mysqlcheck -u $MUSER -h $MHOST -p$MPASS --auto-repair --check --optimize --all-databases
What sort of issues are you having with it? Any error messages, logs? Its hard to look into someone's code whaen you have no idea what you are looking for. cheers
What sort of issues are you having with it? Any error messages, logs? Its hard to look into someone's code whaen you have no idea what you are looking for. cheers
The Xen server we had the script running on would mysteriously start going into swap after a couple couple days. We saw this in top, but the strange thing is that neither top nor ps showed any processes using all that memory (1.5Gb).
On the Parallels server memory wasn't running out, but after a couple days the server would restart on its own.
This script is one of the few things that the servers have in common, and when we remove the script those issues go away (or at least they seem to have).
I have run this manually. It runs fine with no errors whatsoever. None of the server logs showed any errors either. This is what's so confusing about the whole thing. Everything is fine except for the fact that after a couple days the server is blasted. In Xen we saw memory shoot through the roof (with nothing in ps or top to indicate what was using all the memory) and in parallelz the server just reboots. After removing the script everything seems to be fine. Both servers have run a week with no issues. The same script runs on a third openvz server (but only once a day as opposed to once an hour) just fine.
To give you more background, I've been using Linux for several years, I'm comfortable with BASH, and I configure servers and do this stuff all the time. I wouldn't post if this didn't confuse the heck out of me. I simply don't see how such a simple script could cause these massive failures, yet the fact remains that removing the script solves the issues. So, I'm posting here with the hope that someone with more experience in web server scripts can provide any insight into what may be going on.
You have as much information as I do. Any ideas are appreciated.
I have run this manually. It runs fine with no errors whatsoever. None of the server logs showed any errors either. This is what's so confusing about the whole thing. Everything is fine except for the fact that after a couple days the server is blasted. In Xen we saw memory shoot through the roof (with nothing in ps or top to indicate what was using all the memory) and in parallelz the server just reboots. After removing the script everything seems to be fine. Both servers have run a week with no issues. The same script runs on a third openvz server (but only once a day as opposed to once an hour) just fine.
To give you more background, I've been using Linux for several years, I'm comfortable with BASH, and I configure servers and do this stuff all the time. I wouldn't post if this didn't confuse the heck out of me. I simply don't see how such a simple script could cause these massive failures, yet the fact remains that removing the script solves the issues. So, I'm posting here with the hope that someone with more experience in web server scripts can provide any insight into what may be going on.
You have as much information as I do. Any ideas are appreciated.
mysql could crash the server in some cases and the other one could be the archive part "tar" which could use up the CPU and/or MEM for some weird reason, maybe impossible to backup something or some weird loop. But to be honest I cant test it to tell you for 100% is one of them.
Try more and see maybe somehow u will figure it out.
So do you think the parallelz thing was a coincidence? I suppose anything is a possibility.
Maybe. The only other thing that comes to mind is if the machine becomes over utilized or the disk usage is high enough you might be running into overlapping runs of the script if your db's are fairly large, but even in that case you should be able to see where things are being utilized.
This is my script that someone made for a small fee to freelance, and apparently someone laid out the network. All variables are familiar. Only I have it now with auto-delete like this
DATE="$(date +%Y%m%d)"
if [ $OS = "FreeBSD" ]; then
LOCAL_OLDDATE="$(date -v-14d +%Y%m%d)"
FTP_OLDDATE="$(date -v-6m +%Y%m%d)"
else
LOCAL_OLDDATE="$(date -d '14 days ago' +%Y%m%d)"
FTP_OLDDATE="$(date -d '4 mouth ago' +%Y%m%d)"
fi
echo "Dumping MySQL databases..."
${MYSQLDUMP} -u${MYSQLU} -p${MYSQLP} --all-databases > ${BACKUP}/mysql.sql
echo "Back up files and dirs..."
${TAR} czf ${BACKUP}/${DATE}.tgz --exclude='*.mp3' --exclude='*.MP3' ${FILE} ${BACKUP}/mysql.sql
echo "Done..."
cd $BACKUP
DUMPFILE="${DATE}.tgz"
cd $BACKUP
DUMPFILE="${DATE}.tgz"
echo "Put backup archive to remote FTP server"
$FTP -n $FTPS <<END_SCRIPT
quote USER $FTPU
quote PASS $FTPP
prompt off
binary
cd $FTPD
mput $DUMPFILE
delete ${FTP_OLDDATE}.tgz
quit
END_SCRIPT
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.