Tomasz Korwel
programmer, administrator, engineer – my everyday fights with reality

October 18th, 2011

Find and replace within multiple files

Posted by tomasz in tips & tricks vault

I can’t remember how many times I needed this line recently. I also could never remember it (hm… do you see a pattern here?). So here it is for future reference:

find . -name "*.php" -print | xargs sed -i '.backup' 's/foo/bar/g'

It’s pretty much self explanatory. If I could only make it stick in my brain.

July 21st, 2011

Mediacom, are you kidding?

Posted by tomasz in Customer satisfaction

I’ve got internet from Mediacom. Nothing fancy just basic service, but I use it for work and I rely on it every day. Today the connection just died. Technical problems happen so I called support number.

And here was first surprise of the day. They have an automated system that guides you through some troubleshooting steps and is apparently even able to do some magic on their part to reset the line. As I was readying myself to write something nice about Mediacom’s system the helpful (!) computer decided that he can’t help me but will transfer gathered information to live technician so we can continue troubleshooting. Fine.

With the exception that technician started asking me exactly the same questions I’ve already spent 10 minutes answering to the machine. Helooouuu! Second strike. After five minutes of back and forth battle about why the technician needs my private information (like neck size, grandma’s weight, ssn number and email) to record repair request the time as come to schedule an appointment as apparently there was something with my modem and I needed a home visit.

As a side note I was relatively calm until that moment. But when he said that the first available time to schedule the appointment is August 2nd I simply lost it. 12 days without internet? When I needed to start the service they have found available technician within 24h, but it takes 12 days to diagnose and fix my line?

You’ve got to be kidding.

July 21st, 2011

Ubuntu NAS vs. OS X Lion 10.7

Posted by tomasz in Home brew NAS, tips & tricks vault

Today when I woke up my MacBook greeted me with very unpleasant alert:

The network backup disk does not support the required AFP features.

It turnes out that during the upgrade to Lion Apple used their newest set of commands that were not compatible with stable netatalk package in Ubuntu.
To get my network storage to work again I had to upgrade to the latest netatalk 2.2.beta4.

First download all needed files from Ubuntu’s repositories

wget http://launchpadlibrarian.net/73070555/netatalk_2.2~beta4-1_amd64.deb
wget http://launchpadlibrarian.net/74978789/libgcrypt11_1.5.0-1_amd64.deb
wget http://launchpadlibrarian.net/75629511/multiarch-support_2.13-9ubuntu3_amd64.deb
wget http://launchpadlibrarian.net/72120162/libgpg-error0_1.10-0.3ubuntu1_amd64.deb
wget http://launchpadlibrarian.net/74358655/libdb5.1_5.1.25-11_amd64.deb

Then install it:


dpkg -i multiarch-support_2.13-9ubuntu3_amd64.deb
dpkg -i libgpg-error0_1.10-0.3ubuntu1_amd64.deb
dpkg -i libgcrypt11_1.5.0-1_amd64.deb
dpkg -i libdb5.1_5.1.25-11_amd64.deb
dpkg -i netatalk_2.2~beta4-1_amd64.deb

I’ve chosen to keep old version of configuration files, the only notable difference was that now afpd.conf lists -tcp -noddp options as defaults. I added them to my list. Quick restart of netatalk daemon and voila – Time Machine works again.

May 17th, 2011

Incremental daily backup with little space penalty – Time Machine on linux

Posted by tomasz in Home brew NAS, tips & tricks vault

I am a fan of Apple’s Time Machine backup system since it’s introduction. And I’ve always wanted to implement something similar on my server. Since I have that nice spacious NAS disk right now space stopped to be a problem (at least for a little while). Little googling shows that rsync has a special option allowing me to implement Time Machine’s method of incremental backups using rsync. In that method rsync uses existing backup as additional source for comparing files and if file did not change since last backup has been done a hard link is being created to this file instead of copying. This way I should end up with daily directories of files but only new/changed files will be eating up disk space.

Let’s give it a try. My backup script looks like this:

#!/bin/bash
date=`date “+%Y-%m-%d”`

#Mysql dump
for i in /var/lib/mysql/*/; do
dbname=`basename $i`
/usr/bin/mysqldump -u root -pyourpasshere $dbname | gzip -c > /home/mysql/$dbname-$date.sql.gz
done

#Rsync
rsync -arpvogDtSWz \
-e “ssh ” \
–delete \
–link-dest=../mysql-current \
./mysql/ \
root@nas:/path/to/backups/mysql-$date

#Moving links up one day
ssh root@nas \
“cd /path/to/backups/ && rm -f mysql-current && ln -s mysql-$date mysql-current”

The script dumps all dbs to a directory on hard drive, then rsyncs this directory with dated folder on a nas server using mysql-current (which is a symlink to latest daily backup) as additional sorce of files (–link-dest parameter).

I’ve run the script and then checked out the results:

root@nas# du -sh mysql-*
92M mysql-2011-05-16
19M mysql-2011-05-17
512 mysql-current

Looks like indeed the disk usage of the newer directory reflects only today’s copies of dbs. To confirm that hard links work as they should I deleted one file in the oldest directory. And now:

root@nas# du -sh mysql-*
86M mysql-2011-05-16
25M mysql-2011-05-17
512 mysql-current

the older directory size dropped but the newer directory size went up as the same file was hard linked there too and now that directory represents the only physical copy of the file on disk.

That’s exactly what I wanted to achieve.
Now to fully implement Time Machine mechanisms I need to make a script that will calculate the amount of free space needed on backup drive and delete the oldest backups accordingly until there is enough space available (as you see above simply deleting one file may not free up any hard drive space) to mve on with the transfer.

March 29th, 2011

ubuntu’s librxtx with java-6-sun

Posted by tomasz in HVAC Zoning, tips & tricks vault

If you want to use SUN’s java version with rxtx on any debian derivative system you’d be surprised to discover that jre can’t find rxtx libraries if you installed them using librxtx-java package. It’s because SUN does not adhere to debian naming and placing policies and looks for libraries in wrong place. Quick fix:

cd /usr/lib/jvm/java-6-sun/jre/lib/
cp /usr/share/java/RXTXcomm.jar ./
cd i386
cp /usr/lib/jni/lib* ./

That will make those libs available to SUN’s java and everything should work from now on.

Next Page »
ZEND Certified Engineer
Listed on BlogShares

Tomasz Korwel is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com