Restore MySQL databases from raw *.frm files
I recently needed to restore data from a MySQL server where the host machine crashed and where I unfortunately didn’t have a proper dump backup – all I had was a backup of the MySQL data directory (/var/lib/mysql in case of Debian). After some googling I didn’t find a simple solution how to restore databases out of this backup. The solution which worked in the end was the following: I installed a fresh MySQL server in a virtual machine and replaced its data directory with the one from my backup (I had exactly the same MySQL versions on both machines). This allowed me to access the databases and create proper dumps which I could import in my real server later.
So, step one: in a virtual machine/spare server/local pc/whatever install a MySQL server and replace its data directory:
$ aptitude install mysql-server $ /etc/init.d/mysql stop $ mv /var/lib/mysql /var/lib/mysql.orig $ cp -pr /tmp/backup/mysql /var/lib $ chown -R mysql.mysql /var/lib/mysql
I also checked that file permissions match the normal permissions on Debian MySQL installations. Should be like this:
root@host:/var/lib/mysql# ls -al drwx------ 5 mysql mysql 4096 Mar 1 18:20 . drwxr-xr-x 33 root root 4096 Mar 1 18:20 .. -rw-r--r-- 1 root root 0 Mar 1 18:07 debian-5.1.flag -rw-rw---- 1 mysql mysql 27262976 Mar 1 18:21 ibdata1 -rw-rw---- 1 mysql mysql 5242880 Mar 1 18:21 ib_logfile0 -rw-rw---- 1 mysql mysql 5242880 Mar 1 18:21 ib_logfile1 drwx------ 2 mysql mysql 4096 Mar 1 18:20 database1 drwx------ 2 mysql mysql 4096 Mar 1 18:21 database2 drwx------ 2 mysql root 4096 Mar 1 18:08 mysql -rw------- 1 root root 6 Mar 1 18:08 mysql_upgrade_info
root@host:/var/lib/mysql# ls -al database1 drwx------ 2 mysql mysql 4096 Mar 1 18:20 . drwx------ 5 mysql mysql 4096 Mar 1 18:20 .. -rw-rw---- 1 mysql mysql 65 Mar 1 18:20 db.opt -rw-rw---- 1 mysql mysql 8668 Mar 1 18:20 table1.frm -rw-rw---- 1 mysql mysql 879 Mar 1 18:20 table2.frm -rw-rw---- 1 mysql mysql 1520 Mar 1 18:20 table3.frm
Now you can try to start the server and look if your databases are readable:
$ /etc/init.d/mysql start $ mysql -uroot -p -e "show databases;" Enter password: +--------------------+ | Database | +--------------------+ | information_schema | | database1 | | database1 | | mysql | +--------------------+
If this works, simply dump your needed databases with mysqldump, transfer them to your server and import them normally.
$ mysqldump -uroot -p database1 > /tmp/database1.sql $ scp /tmp/database1.sql user@server:/tmp
On the server:
$ mysql -uroot -p -e "create database database1;" $ mysql -uroot -p database1 < /tmp/database1.sql
And don’t forget to restore the temporary MySQL server to normal operation in case you need it later.
$ /etc/init.d/mysql stop $ rm -rf /var/lib/mysql $ mv /var/lib/mysql.orig /var/lib/mysql $ /etc/init.d/mysql start
MySQL backup user
To create a backup user for MySQL you need at least the following privileges (to use mysqldump):
GRANT SELECT, SHOW VIEW, LOCK TABLES ON *.* TO 'backup'@'localhost';
Authenticate Apache against Redmine with AuthMySQL
For a student project we needed to authenticate an apache host against a MySQL database, in this a case we wanted to handle authentication for a Subversion repository with a Redmine database. I know that Redmine has its own solution for this problem using Redmine.pm, but for some reason that approach didn’t work and we didn’t have the time to bug around with it. This howto is written for the use with Redmine (especially the database view), but you should get the point how to set it up on other environments. The howto was done on an Ubuntu 8.10 box but should work on any other distro as well (except for the module installation). I assume that you got all the other stuff (apache, mysql, …) up and running.
Fetchmail and Sieve with Virtual Mail on Debian Etch
Update: This post is quite old and does not work out of the box with the current ISPMail tutorials. I posted an update here.
When it comes to mail servers, I really like the setup Christoph Haas describes in his Document Howto: ISP-style Email Server with Debian-Etch and Postfix 2.3. One thing I was missing on a server was the ability to automatically generate config files for fetchmail and sieve from the database in order to get mail from other servers and being able to apply server side filters on incoming mail. This howto is based on the mentioned tutorial.
The additional setup is quite simple: 2 more database tables hold the data for fetchmail and sieve rules and a set of PHP scripts called by cron every few minutes fetches the data and writes it into the appropriate config files. For fetchmail, a script creates a .fetchmailrc file in /home/vmail/. For sieve, another script creates a .dovecot.sieve config file for every user who got sieve rules in the database.
Quick and dirty: set up a local PHP and Ruby development environment on Ubuntu Hardy Heron (8.04)
This is a quick and dirty tutorial how to set up a local development stack on a fresh Ubuntu Hardy Heron (8.04) install.
Here is what we will install:
- Apache 2.2
- PHP 5 as apache module
- Ruby 1.8 as apache module & Rails 2.0.2
- MySQL 5
- phpMyAdmin