HowTo Backup Your MythTV Installation
Installing MythTV can be quite a hassle. Re-installing after a disk crash half an hour before that vital episode of Coronation Street is due to install is enough to give anyone PTMTVD (Post Traumatic MythTV disorder). This article describes a strategy for backing up your MythTV system. Note this article does *not* include backing up your video files.
Preparing the Base System.
The overall strategy is to create a system where the operating system and database are on a relatively small partition of around 15 GByte and the recordings are on their own partition. This makes it much easier to make a backup of your MythTV installation onto a usb hard drive, or even DVD’s. You will need a separate backup method for your recordings. I only backup recordings I really care about by copying them onto network storage, which has mirrored hard drives. I then mount the storage device onto my MythTV box via nfs.
Using this system I can rcover from a hard drive failure on my MythTV system in less than an hour.
Partitioning Your Hard Disk.
I usually create three partitions:
- First partition of around 15 GByte, which will hold your Linux distro and the MythTV installation, but not the video files (/dev/sda1).
- Second partition of around 1 GByte. This is used as a swap partition (/dev/sda2).
- Third partition - the rest of the disk. This is used to store all your video files (/dev/sda3).
The actual partition names will vary according to your system configuration.
Install your distro of choice onto a small partition. I usually create a primary partition of around 15 GByte.
Now install MythTV as you would do normally.
Configuring MythTV.
By default MythTV will store your recordings in /var/lib/mythtv, which if you have followed my partitioning suggestion will be on your first partition. If you followed the partitioning suggestion above, you need to alter this to store recordings on th third partition (/dev/sda3).
- Make sure that /dev/sda3 gets mounted at boot time.
- Create a directory to mount the partition and make sure its owned by mythtv:
sudo mkdir /mnt/sda3 sudo chown mythtv.users /mnt/sda3
- Edit fstab and add a line to mount /dev/sda3:
sudo vim /etc/fstab # /dev/sda3 UUID=a13d6e1d-bc06-433a-9209-ffc0dfb622f9 /mnt/sda3 ext3 defaults 0 0
- Either reboot, or mount /dev/sda manually:
sudo mount -a
- Start mythtv-setup and edit the recordings directory to point to /mnt/sda3.
Now your recordings are stored on a separate partition to the operating system and MythTV.
Backing Up The Root Partition.
If you followed the partitioning guide above the operating system and MythTV will be on /dev/sda1, which is 15 GByte. Most of this will be free space, so it should be possible to back up the whole of /dev/sda1 into a relatively small compressed file. There are a number of ways of creating a backup of a partition. The method I use is to boot the computer from a Knoppix CD and use partimage to create the backup onto an external usb hard drive.
Backing Up the Database.
It’s important to take regular backups of the database (mythconverg). All the information about your setup and recordings is held there and you would have a very hard time recreating it from scratch. It’s also important to have several backups, as often it can be a few days before you notice something is wrong and keeping just one or two backups mat result in your backup containing a corrupted database.
I use a script called automysqlbackup . The following is a list of automysqlbackup’s features taken from its web site:
- Backup multiple MySQL databases with one script. (Now able to backup ALL databases on a server easily. no longer need to specify each database seperately)
- Backup all databases to a single backup file or to a seperate directory and file for each database.
- Automatically compress the backup files to save disk space using either gzip or bzip2 compression.
- Can backup remote MySQL servers to a central server.
- Runs automatically using cron or can be run manually.
- Can e-mail the backup log to any specified e-mail address instead of “root”. (Great for hosted websites and databases).
- Can email the compressed database backup files to the specified email address.
- Can specify maximun size backup to email.
- Can be set to run PRE and POST backup commands.
- Choose which day of the week to run weekly backups.
I run the script as a daily cron job and copy the backup directory to another computer on my network. It’s important that you make a copy of the backup to another computer. If you don’t and the hard disk in your MythTV dies, you will have lost your database backup.
Restoring MythTV and the Database.
In the event of a hard drive failure, restoring is simple. You must create partitions on your new hard drive at least as big as the ones on the original drive. It doesn’t matter if you make them larger. You can use any live Linux CD, such as Ubuntu to create the partitions. Once you have created the partitions on the new hard disk, just fire up partimage and use it to restore the back up image of your root partition (/dev/sda1 in my example).
Now you need to restore the most recent backup of the database from automysqlbackup. The backups are stored in compressed format by default, so you need to uncompress it first:
gunzip mythconverg_2007-12-16_09h00m.Sunday.sql.gz
You can then restore the backup to the mythconverg database:
mysql -u mythtv -ppassword < mythconverg_2007-12-16_09h00m.Sunday.sql
Note that there are no spaces between -p and your password (mythtv by default).
11 Comments
Back to MythTV.Backup — Home Page
