Freebsd - Backup & restore for disaster recovery

Data are all around servers.. To name a few, file server, email server, LDAP server, web server, DNS server and these are just a few essential servers that make up part of IT section of your company. ERP, CRM, financial projection system, database server, accounting & payroll system are the example of business application. Imagine, what if "some" of these data are loss. It is also worth mentioning that data is so valuable to the company, that partial loss of it might lead to breaking your business continuity !!!

Most of the company operation are depending on these data in the server to make decisions. Data in the servers have never been so important.

Server data disaster recovery planing is a vital process in system administration. It directly shows how much the system administrators understand the importance their role in the business. Reason for data loss can be classified into 2 main categories, natural disaster and man made disaster. Natural disaster that causes data loss includes flood, earthquake, fire hazard and etc. Man made disaster (aka PBKC which denodes Problem Between Keyboard and Chair :p ) examples, hacking activities, accidental data deletion or over written and server maintenance e.g. patching, upgrades, developments, moving to a bigger size of hard disk & etc.

Disaster recovery involves planning, backup & restore. Planning will need identify which are the crucial data to backup and how frequent should it be backup. The next consideration will be what media should the data be save to. Generally, external hard disk (e.g USB) or network based storage (e.g. file server, ssh server, NAS, SAN) are the cheapest & fastest way to store the data. But if the data is to archive, it should go into media e.g. tape, CD, DVD and other optical media. Lastly, all planning and backup of the data should always test against restoration, or else why even plan to save it. :)

This post will concentrate on how to prepare for Server disaster recovery on a FreeBSD server. Do take note Database backup is not cover in this post as Database backup itself, have already a few strategy to look on.

There is an update for this post, please check out the updated post "FreeBSD – Backup and restore FreeBSD using Fixit CD".


The step by step backup listed below will backup the files to a network based storage server which  transfer through SSH. Since this is a full system backup, server performance will be affected because of the intense read/write of data backup.


1. Backup the hard disk slice with :
dump -0auLf - /dev/<hard disk slice> | bzip2 | ssh <ssh username>@<ssh server> dd of=filename.bz2

where :

0 = backup everything

a = need this if media is a file

u = update /etc/dumpdates after a successful dump

L = use snapshot to workaround file locking

f = the backup file name (notice that the backup file is a "-" which means output it to stdout so that we can compress/zip it later)

/dev/<hard disk slice> = the device node name of the hard disk slice. Which can obtain from the output of "df -h", the first column of the output. e.g. /dev/ad0s1a, /dev/ad0s2d and etc

<ssh username> = ssh server login name

<ssh server> = ssh server IP or FQDN hostname


dump -0auLf - /dev/ad0s1a | bzip2 | ssh bob@server dd of=/home/bob/server-backup/filename.bz2

2. Repeat step 1 for other slice or partition of hard disk


1. Install a fresh new FreeBSD on the new server with the same partition table layout. Size does not matter but logically, the hard disk slice size has to be bigger then the production server data.

2. Reboot the server to make sure it boots properly, with the partition table all created accordingly.

3. Boot into Freesbie live cd and login as root (might need to use the command "su -" to escalate user to root)

4. Find out the partition label using the command :
bsdlabel <hard disk slice>

(Note down the slices  "fstype" of "4.2BSD".)

Example of command, bsdlabel /dev/ad0s1, /dev/ad0s2

Example of output to note down, /dev/ad0s1a, /dev/ad0s2d

5. Mount the partitions noted in step 4  in /tmp

(Why /tmp? Because /tmp is the only place writable to create directory for mount point)

e.g. mount /dev/ad0s1a /tmp/new-root-partition, mount /dev/ad0s2d /tmp/new-var-partition

*** If an error "mount: /dev/ad0s1a: Operation not permitted" pops out after executing
mount /dev/ad0s1a /tmp/new-root-partition

try fsck :
fsck -y /dev/ad0s1a

6. Optional :

Copy the compress backup file from other server (file server, ssh server, NAS, SAN or etc) to a local temporary directory for later to restore.


scp bob@server:/home/bob/server-backup/filename.bz2 /tmp/new-root-partition/

OR restore the backup in this one liner :

cd /tmp/new-root-partition;ssh bob@server bzcat /home/bob/server-backup/filename.bz2 | restore -rvf -

7. Go to the destination partition that the backup will restore to :
cd /tmp/new-root-partition

8. Restore the backup.


bzcat /some/temporary/local/directory/filename.bz2 | restore -rvf -

9. Repeat step 8 to restore other partition, if any.

10. Optional :

Edit the neccessary systems files to reflect the changes (before rebooting the server)





11. Reboot the server.

Voilla !!!

1 comment:

zogness said...

Sadly, this no longer works on FreeBSD 10.