ATTENTION ATTENTION
gear.huuah.com has launched. Visit the shop at http://gear.huuah.com/. Lots of Photo Gear at the moment
ATTENTION ATTENTION
Itsplanned.com is just launched! - Task and project management made easy. Try it for free.

Create your own lists of things to do - arrange the order to do them - move them around - group them

No limitations - all free project management - try the free demo before signing up - demo: itsplanned.com
Restore Debian / (root) from backup and boot it.
15.07.2010

A failing hard drive is something everybody fears. Are all data lost forever or can they be restored from a backup? Hopefully the latter.

I have a setup, where I with the dump/restore utilities on my Debian box are running a set of scheduled backup jobs. To make it short, I use the dump utility to backup the different mount points on my system.

How to backup with dump

To backup the root (/) partition I run a command like this:

dump -0 -u -f - / | gzip > /mnt/backup/root-gziped.gz

This runs the dump utility with a set of options (please referrer to the man page for further options). -0 means a level 0 backup, -u updated a log file with the date of the last update and -f outputs everything to standard output. Afterwards the gzip command will pack the dump data and store it in a file.
This is the way I do it. Feel free to use other options.

How to restore a backup made with dump

If your hard drive is failing or perhaps running low on disk space and you need to upgrade it, one way is to do it by restoring from a backup.

What you need, is some kind of running Unix system where you can access the new hard drive and you also need access to the backup file. I have plugged my new drive in another Unix machine as a secondary drive. In this case I am using an Ubuntu 10.4 workstation, where I have installed the dump utility.

Partitioning the new hard drive

To get access to the new drive we need to partition it first. I am using the GParted program in my Ubuntu and have created a partition layout like this:
GParted
NB. This screenshot shows disk usage, because the screenshot it taken after a successful restore.

Mounting the new layout

Before we can start the restore, we need to mount the new partition. This is done from the console (terminal) like this:

#mkdir /media/root

#mount /dev/sdb1 /media/root

NB. Please note that I am using sdb (and not sda like the screenshot above shows). This is because the hard drive is not the system drive yet.

The hard drive is now mounted in the /media/root directory and we can begin the restore.

Restoring data

I am using the restore command with the interactive shell to select the files and directories that I need to restore.

# gunzip root-gziped.tar.gz  | restore -ivf -
Verify tape and initialize maps
Input is from a local file/pipe
Input block size is 32
Dump   date: Thu Jul  8 21:35:37 2010
Dumped from: the epoch
Level 0 dump of / on myserver.mynetwork.com:/dev/sda1
Label: none
Extract directories from tape
Initialize symbol table.
restore >

At the prompt it is possible to browse the media with the normally used ‘cd’ and ‘ls’ commands. When we have found what we need we can go ahead a add it to the queue. To help the restore utility getting the folder permissions correct I usually runs the command setmodes as the first thing.

restore > setmodes
Set directory mode, owner, and times.
restore > add boot
restore > add bin
...
...
restore > extract

The ‘add’ command adds folders or files to the queue and the extract command will start the restoring process.

When this is finished you will be asked if you want to set folder permissions on ‘.’. Answer Yes here.

...
Add links
Set directory mode, owner, and times.
set owner/mode for '.'? [yn] y
restore >

This is it. The files are now restored and the hard drive is almost ready to begin its new life.

Installing grub boot loader

Before the disk can boot up and start the operating system, it needs to have a boot manager. My previously system was using Grub, so I will just reinstall this on the new drive. For this job, we can use an Ubuntu Live cd-rom and boot this.

When this is done and the Ubuntu Live version has booted we need to get access to the new drive (now known as /dev/sda).

Open up a terminal window and enter:

#mkdir /mnt/root

#sudo mount /dev/sda1 /mnt/root

#sudo chroot /mnt/root /bin/bash

#grub-install /dev/sda

These commands will create a mount point, mount the new drive, get root access to the new content and install a grub boot loader on the new.

Power off the machine, pull out the hard drive and install it in the old server again.

Leave a Reply