MySQL replication

More brain dumping, this time after setting up MySQL on my test server to replicate offsite as the data on there is becoming important.

To start with both machines are running fully updated and upgraded Debian Etch and MySQL 5 as a Debian package with identical copies of the MySQL databases in /var/lib/mysql/.

On the master I:

I ensured that bind-address was set to the machine’s IP address as by default it is bound to localhost (therefore not allowing external connections) in /etc/mysql/my.conf

Checked that the server-id and log_bin were set in /etc/mysql/my.conf

Issued the MySQL command GRANT REPLICATION SLAVE ON *.* TO 'USERNAME'@'SLAVE_IP' IDENTIFIED BY 'PASSWORD';

Issued the MySQL command FLUSH TABLES WITH READ LOCK; and then SHOW MASTER STATUS;, noting down the values of File and Position.

On the slave I:

Checked that the server-id and log_bin were set in /etc/mysql/my.conf (server-id being different to that of the master)

Issued the mysql command:

CHANGE MASTER TO MASTER_HOST='MASTER_IP',
MASTER_USER='USERNAME',
MASTER_PASSWORD='PASSWORD',
MASTER_LOG_FILE='FILE_NOTED_EARLIER',
MASTER_LOG_POS=POSITION_NOTED_EARLIER;

To check it was all working I used a combination of the MySQL command SHOW SLAVE STATUS; ensuring that all looked OK and simply made changes on the master and saw them appear on the slave.

If the slave is constantly showing “trying to connect” to the master when you show status then to debug make sure that it can telnet to 3306 on the master. If not then you have to ensure that there is network access between the machines and re-check the bind-address on the master.

Search and replace multiple files with sed

Ok, if you ‘do’ linux then you’ll probably already know this one. I did, kinda, but had to Google to remind myself of the exact chain of commands. So here I am writing it down so it’s easier to find next time.

In my case I had a load of apache conf files where I needed to replace each occurence of an IP address with an asterisk. A combo of find and sed worked well:

find /etc/apache2/sites-available -type f -exec sed -i 's/192.168.255.2/*/g' {} ;

Moving multiple subversion repositories

I had a need to migrate all of our subversion repositories from an overworked machine onto a new dedicated machine. As I had about 30 repositories to copy over I didn’t fancy doing each dump -> copy -> create -> import manually so I came up with the following. Which, amazingly, worked first time. I’d say a total of an hour elapsed from sitting down to start the job to being finished.

FWIW I’m running Debian Woody on the old machine and Debian Etch on the new one. Subversion was already installed on the new machine.

So, on the current svn server, dump out all of the repositories:

cd /export/svn
mkdir ../svn.dumps

for REPO in `ls`; do svnadmin dump $REPO > ../svn.dumps/$REPO.dump; done

Now copy over to the new machine. Ok, you *could* gzip each one first but I didn’t mind having to wait whilst it copied over.

cd ../
scp svn.dumps/* root@<other machine>:/export/dumps

On the new server su to root then and create the new repositories, import the dump files, change ownership and fix the file permissions:

su -
cd /export/dumps

for REPO in `ls | sed -e '/.dump/s/.dump//g'`; do
svnadmin create /export/svn/$REPO;
svnadmin load /export/svn/$REPO < $REPO.dump;
chown -R svn:svn /export/svn/$REPO;
find /export/svn/$REPO -type d -exec chmod 2770 {} ;
done

(wait quite a while)

Then create /etc/subversion/passwd and fill it with the contents from the old server.

Now you can either check out the projects again, or even easier (I didn’t script this bit) switch the location within the checked out project, for example:


cd /your/sandox/project/
svn switch --relocate svn://old/sever/repos/trunk svn://new/sever/repos/trunk

Job done.

Actually no

It turns out that I lied and there was one small thing that broke, I forgot to configure the authentication method on each repository in turn so you’d currently only have read access. To fix this all we need do is:

su -
cd /export/svn

for REPOS in `ls`; do echo "password-db=/etc/subversion/passwd
realm = YOUR REALM" >> $REPOS/conf/svnserve.conf; done

Which ensures that for each repository svn will use your central password file

Move multiple subversion repositories

Need to move multiple subversion repositories?

Well I just finished putting a simple how-to together which details the steps I took when moving our 30+ svn projects from one server to another.

It went really smoothly and took about a quarter of the time I was expecting it to.

Anyway, here it is.

Related:

A Blank WordPress Theme

I’ve just uploaded a blank WordPress theme called Naked that I built to assist those (like myself in the past) who have a need to quickly roll-out a WordPress theme with a custom look and feel but may not necessarily have the time to start from scratch.
It is purposely very simple and basic, but I’ve put some effort into making it self explanatory and for anyone with experience of PHP/XHTML/CSS it should be an absolute doddle to use.

Here’s the default look, woo!

screenshot.png

You can download it here, enjoy.

Removing DOS linebreaks from your files using Vim

This morning I’m debugging an issue on a script that gets cronned every minute. I’ve a shell open on the server and the file in question open using Vim and I notice each line has a trailing ^M…. Aargh the dreaded DOS linebreak.

Dusting off my rusty vim-foo I simply do a search and replace using Vim without having to exit the file.

The command is:

:%s/^M//g

Job done, well actually no, there is still an issue with the script but now I at least know that ^M is not the culprit.

Note: To get the ^M I did NOT type a caret and M, I typed Ctrl-V then Ctrl-M

Family tree stuff

My old man has been getting into finding out more about our family history. Most of his research so far has been by talking to one of my second cousins in Lowestoft who as already done a fair bit of digging. Through her he’s found out that his Mum originated from Cheltenham (I always thought she was born and bred Welsh) and her family name, Pritchard.

Anyway, not being one who can tell the front from the back of a computer he genuinely impressed me the other day when he told me to Google for Cheltenham fire brigade which I then did coming up with this page.

oldfire.jpg

This is the first picture taken from that page and amongst others it shows a C and a W Andrews. Apparently C Andrews is my great great uncle and W Andrews is my great great grandfather (my Nan’s grandfather).

Fascinating (if you’re me).