Backup all MySQL databases to gzip individually with mysqldump

I was always kind of disappointed with the mysqldump cron jobs I saw published because they always threw everything into a single backup file. Alternately I could call out each db individually, but that meant if I added another mysql database I had to update my script. When I started looking for shell scripts that I could run as a cron job (as opposed to say commercial tools, stored procedures, etc.) I kept coming up empty. So I came up with the following that backups all databases individually and then deletes any backups older than 30 days:


DATE=`date '+%F'`

ls -l $MYSQL_DATA -I mysql | grep ^d | awk '{print $9}' >> $TEMPFILE
DIR_LIST=( `cat "$TEMPFILE" `)

for i in "${DIR_LIST[@]}"
        mysqldump -u <mysql_backup_user> -p<password> $i | gzip > /backup/$i.$DATE.sql.gz

mysqldump --events -u <mysql_backup_user> -p<password> mysql | gzip > /backup/mysql.$DATE.sql.gz

rm -rf $TEMPFILE
find $MYSQL_BACKUP/*.gz -type f -mtime +30 -exec rm {} \;

iTunes Won’t Close on Windows 7

This one was an easy fix though took me a bit to track down. Start -> Run -> services.msc and disable the Bonjour Service. Either through a bug in the music sharing component of iTunes or just a “helpful feature,” it won’t let you exit iTunes while the Bonjour service is running.

Install NRPE for Nagios on CentOS 6.2

useradd -m nagios && passwd nagios
mkdir ~/downloads && cd ~/downloads
yum install -y wget openssl-devel xinetd && yum groupinstall -y "Development Tools"
wget && tar -xzvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15 && ./configure --enable-command-args && make && make install
chown -R nagios:nagios /usr/local/nagios/
cd ..
wget && tar -xzvf nrpe-2.13.tar.gz
cd nrpe-2.13 && ./configure --enable-command-args && make all && make install-plugin && make install-daemon && make install-daemon-config && make install-xinetd
vi /etc/xinetd.d/nrpe
vi /etc/services
vi /usr/local/nagios/etc/nrpe.cfg
service xinetd start

Resizing LVM Mounts

A common problem for me has been needing to resize an LVM partition. This works fine if you’re dealing with a non-critical mount point like /home that you can afford to take down while the system is online, but what if you need to resize /usr or /var for instance? The easiest method I found is to utilize the CentOS 6.2 LiveCD – it has all of the tools you need out of the box so there’s no need to install extra packages to make it work. Say you wish to steal 1G from /var and add it to your / partition. You’ll need to note the physical location of those mount points (a quick cat of /etc/fstab will yield you that). For me, / was mounted to /dev/mapper/VolGroup00-LogVol00 and /var was mounted to /dev/mapper/VolGroup00-LogVol03. Boot in through the LiveCD and run the following as root:

e2fsck -f /dev/mapper/VolGroup00-LogVol03
resize2fs /dev/mapper/VolGroup00-LogVol03 1G
lvreduce -L -1G /dev/mapper/VolGroup00-LogVol03
lvextend -L +1G /dev/mapper/VolGroup00-LogVol00
e2fsck -f /dev/mapper/VolGroup00-LogVol00
resize2fs /dev/mapper/VolGroup00-LogVol00

Iterate Through Directories and Backup SVN Repositories

I found this useful as I have quite a few SVN repositories that I’m responsible for maintaining. Due to the large number I didn’t want to manually specify each directory in an array as that involved more upkeep that I really wanted to have on my plate. This script will go through a target parent directory and perform an svnadmin dump on each repository to a gzipped file in the target backup directory. So for example if all of your svn repositories reside in /srv/svn and you want your gzip files to end up in /home/backup then create a shell script from the below info and set SVN_PARENT=/srv/svn and SVN_BACKUP=/home/backup. Right now I only care about keeping a day of backups so this script deletes all of the backup files prior to performing the next round of backups. Delete that line if you’re looking to keep a larger backup history.


DATE=`date '+%F'`

DIR_LIST=( `cat "$TEMPFILE" `)

rm -rf $SVN_BACKUP/*.gz

for i in "${DIR_LIST[@]}"
        svnadmin dump $SVN_PARENT/$i | gzip > $SVN_BACKUP/$i.$DATE.svn.gz

rm -rf $TEMPFILE

Copyright © All Rights Reserved · Green Hope Theme by Sivan & schiy · Proudly powered by WordPress