Brent Dax (brentdax) wrote,
Brent Dax

  • Mood:

How to fix a database using as many Linux features as possible!

Task: Repair a damaged database.

Constraint: The server it's residing on doesn't have enough space to repair it. The Linux partitions on the client are too small; there's an NTFS partition with enough space, but Linux cannot change the size of files on such a partition. SMB is far too slow to simply mount the NTFS partition to the server and use it as scratch space--or even to copy the file over, repair it under Windows, and copy it back.

Solution: Create a big file on the NTFS partition (in Windows), put an ext2 filesystem in it, and use the loopback device to mount it. Then copy the file to the scratch filesystem with NFS, repair it, and copy it back.

Step 1: perl -e "open (TEMP, '> c:\temp.ext2'); for(0..5*1024*1024) { print qq(\r), int($_/1024); print TEMP qq(\0) x 1024 or die $! }" (Generates a 5GB file.)
Step 2: Boot into Gentoo
Step 3: emerge nfs
Step 4: ssh navi, then /etc/init.d/apache stop; /etc/init.d/mysql.server stop; emacs /etc/exports; /etc/init.d/nfs start
Step 5: mount navi:/ /mnt/navi
Step 6: mke2fs /mnt/win/temp.ext2
Step 7: mount -o loop /mnt/win/temp.ext2 /mnt/temp
Step 8: cp /mnt/navi/var/mysql/apache/access_log.* /mnt/temp
Step 9: emerge =mysql-4.0.17
Step 10: myisamchk -r /mnt/temp/access_log
Step 11: cp /mnt/temp/access_log.* /mnt/navi/var/mysql/apache
Step 12: ssh navi, then /etc/init.d/mysql start; /etc/init.d/apache start

And it worked, with only minor problems (mainly relating to NFS configuration). It was almost too easy, once I figured out how to do it.

  • Paging madlori (and anyone who knows her)

    An interesting thing just happened on Facebook chat. Lori Summers [2:29:44] Got my message ? Brent Royal-Gordon [2:33:45] I did. Lori Summers…

  • guest post

    kate is the best better than the rest the best the best haikus about kate: kate's my favourite i want to lick her ballsack it would taste so…

  • Practice

    This December, I will have been practicing programming seriously for ten years. That will mark the tenth anniversary of me starting to learn Perl. I…

  • Post a new comment


    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 1 comment