FileMerge Command Line Tools for Subversion

written by Paul on March 21st, 2008 @ 12:44 AM

Here are some pretty useful tools for using FileMerge on OSX with the command line subversion.

I stumbled across these tools while I was looking around at how I can better use FileMerge with Subversion

Here is what I did to fully set them up.


# sudo su
# cd /usr/bin
# svn export http://ssel.vub.ac.be/svn-gen/bdefrain/fmscripts/fmdiff .
# svn export http://ssel.vub.ac.be/svn-gen/bdefrain/fmscripts/fmdiff3 .
# svn export http://ssel.vub.ac.be/svn-gen/bdefrain/fmscripts/fmresolve .
# exit
# vim ~/.subversion/config

Be sure to set your diff and diff3 tools to use the fmdiff and fmdiff3

Thanks Bruno De Fraine for publishing these great tools and making my life a little easier. :)

Bulk Zone file Serial Number Increment

written by admin on January 18th, 2008 @ 01:25 AM

I have way too many domain names, so that means that when I want to make a change to my zone template files including a search and replace for certain ips or just changing the email in the zone like I do below. (Or whatever you need to do.)

I first backed up my zone files with a basic but effective cp command:

blah@server ~# cp /var/named /var/named-backup

Then I replaced my email with one that would handle the spam and put it in the right mailbox (/dev/null.) :)

blah@server ~# for file in $(ls /var/named/*.db); do sed -i "s/paul.mydomain.com/dns.omniop.com/g" $file; done

Now that all of the zone files are updated, even if I were to restart my named, the files would not update my slave DNS servers because the serial number in the zones have not changed.

...
2008011502    ; serial, todays date+todays
...

So here is a quick little shell script that I wrote that increments all of my BIND zone files for my DNS server.

#!/bin/bash
for file in $(ls /var/named/*.db);
do
  if [ -f $file ];
  then
    OLD=`egrep -ho "2008[0-9]*" $file`
    NEW=$(($OLD + 1))
    sed -i "s/$OLD/$NEW/g" $file
    echo "fixed $file" 
  fi
done

There may be a better way of doing this, but I found this very quick and painless.

Now I will hopefully get less spam now that the DNS email scrapers won’t get my email from my zone files.

Hope this helps someone!

VPS restoration from backup kills your InnoDB database -- don't let it happen to you!

written by Paul on January 11th, 2008 @ 12:56 AM

A month ago my then VPS provider, JaguarPC, has some really freaky hardware issues, that to this day I have no idea what happened and they ended up restoring a two week old backup of the whole server which included my VPS. When I fired up this blog and a couple of other sites they failed due to mysql table corruption. The corrupt databases that used Myisam tables seemed to repair just fine, but all of my InnoDB databases (Rails uses InnoDB by default when you use migrations) were unrecoverable and I ended up having to try other means for getting my data back or at least as much of my data that I could get back.

Here is what I learned:

  1. Never assume that your hosts backups of your VPS will work when they are restored because they perform backups while the server is running and databases don’t like that too much.
  2. Always keep backups of your databases, especially the ones that use the InnoDB table engine, in a SQL dump format.

So here is what I do now to prevent this from happening again:

  1. Perform your own backups of your databases using the methods that are suggested for your db and db table engines.
  2. Get the data into SQL so when your VPS is backed up it will properly backup a dump.

Assuming that you have a file that contains a list of databases with one per line, you can do something like the following and then hook up your script t cron.

#!/bin/bash

cd /var/lib/mysql

if [ ! -d sql_backup ]; then 
  mkdir sql_backup
fi

for db in $(cat databases.txt); do echo $db; mysqldump --single-transaction $db > sql_backup/${db}.sql; done

Good luck, and oh BTW, you might want to get this running on your VPS before your host does the restore. ;)

MySQL on the move from Latin1 to UTF8

written by Paul on January 25th, 2007 @ 12:45 PM

A few days a go I had to move a Wordpress blog from one server to another and it turned out to be a bigger project than I had originally thought due to the character set being set to Latin1 on the old server and about 180+ posts that were copied in from Microsoft Word containing strange opening and closing quotes and hyphens. When I did a dump of the database and then reimported the data in to a utf8 database man strange characters showed up in the post. I did what I usually do in situations and started to Google for an explanation. I found this article and it referenced this article and here is what I ended up doing to get the issue solved.

I opened up the raw sql dump file in less and saw the strange characters in the test and they looked something like this:
Don<C3><A2><E2><82><AC><E2><84><A2>t

I looked at the context of the skewed characters and saw immediately that it was an apostrophe that was made "special" by Word and then copied into Wordpress. I removed the "< " and ">" and got C3A2E282ACE284A2 which I then put in the queries that were posted on the articles that I read (links above.)

I repeated the above steps until all of the strange characters were fixed, If you are reading this because you are trying to do the same fix you may find the below helpful.



-- C3A2E282ACE284A2 = ' (apostrophe)
UPDATE wp_posts SET post_content = REPLACE(post_content, UNHEX\('C3A2E282ACE284A2'), "’") WHERE post_content REGEXP UNHEX('C3A2E282ACE284A2');


-- C3A2E282ACC29D = " (close quote)
UPDATE wp_posts SET post_content = REPLACE(post_content, UNHEX('C3A2E282ACC29D'), "\"") WHERE post_content REGEXP UNHEX('C3A2E282ACC29D');


-- E28099 = ' (another form of a singe quote)
UPDATE wp_posts SET post_content = REPLACE(post_content, UNHEX('E28099'), "'") WHERE post_content REGEXP UNHEX('E28099');


-- C382C2B4 = ' (yet another quote)
UPDATE wp_posts SET post_content = REPLACE(post_content, UNHEX('C382C2B4'), "'") WHERE post_content REGEXP UNHEX('C382C2B4');


-- C3A2E282ACC593 = " (open quote)
UPDATE wp_posts SET post_content = REPLACE(post_content, UNHEX('C3A2E282ACC593'), "\"") WHERE post_content REGEXP UNHEX('C3A2E282ACC593');


-- C3A2E282ACE2809C = - (dash/hyphen)
UPDATE wp_posts SET post_content = REPLACE(post_content, UNHEX('C3A2E282ACE2809C'), "-") WHERE post_content REGEXP UNHEX('C3A2E282ACE2809C');


I hope posting this helps someone save a few hours of hunting around. :)

Installing RMagick on OSX

written by Paul on September 2nd, 2006 @ 12:26 AM

I am working on a little app (link coming soon) with a friend of mine in an effort to practice my rails and now Rmagick skills since my day job doesn't allow me the opportunity.

One of the things that I am building is an logo generator so I need to have an image manipulator/generator of some sort. I have used ImageMagick on many projects in the past so I looked forward to spitting out the classy logos uswing Rmagick.

Like most open-souce installs on OSX and Linux there were some issues that came up along the way.

I first ran the following command on my OSX terminal but got a couple of errors.

# sudo gem install RMagick
...
Can't find Magick-config or GraphicsMagick-config program.
...

I fixed this error by installing the imagemagick-dev version as opposed to imagemagick.

Then when I tried it again I received this error:

...
Can't install RMagick. Can't find libMagick or one of the dependent libraries
...

I resolved this error by searching google and finding this thread so I told fink (one of my osx package managers) that I wanted it to build imagemagick from source with the following command:

# fink --no-use-binary-dist install imagemagick-dev

After I rebuilt ImageMagick form source and inclused all of the dependent libraries i was able to successfully run the following command with no problems:

# sudo gem install RMagick

It worked! Yeah!

Now I will get back to the Rmagick docs. :)

Options:

Size

Colors