[Previous] [Contents] [Index] [Next]

Making Backups

This chapter covers the following topics:


This chapter deals with making a copy of your data to guard against hardware, software, or human error that may destroy the original. If your data is important to you, you should follow a backup routine that would allow you to restore lost data with minimal cost to you in time and money.

Remember: hard disks do fail and people do make mistakes. It's too late to start a backup after your data is gone!

You can back up an entire filesystem or only portions of it. Users may elect to back up their own files only, usually to floppies. To back up large portions of the filesystem with files owned by many users, you'll need to have read permissions on these files. The superuser (root) has such privileges.

When to back up

You should back up often enough so that you can recover data that's still current or can be made current with minimal work. In a software development group, this may range from a day to a week. Each day of out-of-date backup will generally cost you a day of redevelopment. If you're saving financial or point-of-sale data, then daily or even twice-daily backups are common. It's a good idea to maintain off-site storage.

Backup formats

QNX supports a variety of backup formats that can be classified into two groups:

An archive consists of one or more files, merged into a single unit with its own directory of contents. This single unit can be saved either to a regular QNX file or to a raw block device like a floppy or tape.

Saving to a regular filesystem simply involves copying the files. In this case, the destination must be a device with a mounted QNX filesystem on it.

Archive backups

QNX supports three major archive utilities:

Both cpio and tar are implemented as links to pax, which is capable of reading and writing both cpio and tar formats. Both cpio and tar are common on UNIX systems. The pax utility is a cover utility for cpio and tar, so it doesn't support its own archive format. By default, pax will use the tar format when creating an archive.

The pax utility will detect when you've reached the end of a disk or tape on a volume and will prompt you to insert the next volume to be used for the save. The result is a backup spanning several media (disks, tapes, etc.).

Naming volumes

Unfortunately, the tar/cpio format does not label the media with volume IDs. If you mixed up your media or inserted the wrong one out of order, you would end up restoring bad data.

To safeguard against this possibility, QNX is shipped with the vol utility, which labels each disk volume with its sequence number and therefore prevents you from inserting out-of-sequence media.

Note: The vol utility can be used with floppies or removable disks. This utility isn't for use with tape systems.

The vol utility will, by default, step over block one of all media. This is important for floppy diskettes and cartridge disks that contain a QNX signature in block one. The signature contains the size of the diskette (360K, 1.2M, 1.4M, etc.) and allows for automatic remounting of removable media by the filesystem.

We ship QNX distribution diskettes using pax to create an archive, freeze to compress the data, and vol to write to floppies.

Note: If you wish to save data for restoration on a UNIX system, don't use freeze or vol: you won't find those utilities to do the restore at that end. Instead, use pax to save and restore directly to the target media.

Filesystem backups

You back up to a filesystem by copying files, probably with the cp utility or with cpio -p. If your destination is a floppy, the cp utility will prompt you for more diskettes, but remember that no single file can be larger than the diskette's capacity. If you wish to back up to floppy, we recommended that you use one of the archive utilities.

Backup media

Your choice of backup media will be determined by available hardware and cost. Here are some common choices:

QNX provides drivers for several SCSI controllers. These drivers scan for hard disks, sequential-access tape units, WORM (write once/read multiple) devices, CD-ROM drives, and optical drives.


Floppies are the most widely available device for personal backups. Their major shortcoming is their limited size. Since the QNX pax and vol utilities let you span media, your only concern will be having to feed several floppy diskettes into the drive. If you have to deal with more than four or five floppies, this will make the procedure unpleasant enough that you may stop doing it regularly! You might want to consider compressing your data as described below.

In order to back up/restore from a floppy diskette, you must make sure the floppy driver (Fsys.floppy) has been started (see Fsys.floppy in the Utilities Reference.

The following command will start the floppy drive (assuming that Fsys is already running):

Fsys.floppy &

By default, Fsys.floppy creates a block special device for floppy drive 0 (/dev/fd0). If your machine has more than one floppy drive, Fsys.floppy creates a block special device for each. For example, drive 1 would map to /dev/fd1.

Archiving data to floppy

When you use an archive utility for your backups, it reads and writes directly to the first block. Because tar writes archive data directly to the first block, the first block on the diskette will contain 512 bytes of raw data. This could pose a problem for Fsys.floppy, which attempts to read the first block on all floppies for the QNX signature.

To prevent unpredictable behavior when archiving data or restoring archived data from floppy diskette, run the lockfd utility before you start. The lockfd utility causes Fsys.floppy to lock the driver to a specific media size and suppresses the driver's attempt to read signature information from the first block if the data has to be restored from floppy.

Copying files to floppy

You must format and initialize any unformatted diskettes before you can mount the floppy device and copy files to the floppy. The following example would initialize a high density 31/2" floppy diskette:

fdformat -s 1.4m /dev/fd0
dinit /dev/fd0

To mount a filesystem on the block special device:

mount /dev/fd0 /fd0

You may now treat the floppy as a QNX filesystem mounted as /fd0. To copy files to the floppy, use the cp utility.


To back up/restore from tape, you must make sure the correct driver has been started. This will typically be one of the SCSI drivers described in the Utilities Reference.

For example, if you have an Adaptec 1540-compatible SCSI controller with an attached tape drive, the following command will start the driver and register a sequential-access tape unit as /dev/tape1:

Fsys.aha4scsi fsys -n 1=tape

The archive utilities (e.g. tar, pax) will read and write directly to the tape's block special file. You can't mount a filesystem on this type of block special file.

Note: Currently, the QNX 4 filesystem is limited to handling 512-byte records. To ensure proper streaming performance with tape devices, you may need to increase the blocking factor by using the -b blocking option to tar or pax.

For example, the following command:

pax -w -b63b -t /dev/td0 .

performs a backup of the current directory to tape using the maximum blocking factor with pax.

When the AHA 4 driver receives a request to read or write, it does so by starting at the current tape position. If you're starting a new backup, you'll need to erase and rewind the tape.

A number of tape position and control functions are provided by the tape utility, which is described in the Utilities Reference. For example, the following command would rewind, erase, then rewind the tape in preparation for an archiving procedure:

tape rewind erase

Removable disk

Removable hard disks are popular in both magnetic and optical formats. Many units use a SCSI interface to the computer, so you may want to consider making your internal fixed disk a SCSI drive (then you won't need a second controller and driver).

Unlike floppies and tapes, a removable hard disk lets you avoid using the archive utilities like tar. Instead, you'd likely use cp or pax -rwto copy your data to a real filesystem on the cartridge. This allows you to recover single files very easily and quickly.

Fixed disk

You can place a second hard disk in your machine for online backups. As an alternative, you could consider making backups to a hard disk on another machine in the network. However, backups across the network are slower than backups to a local hard disk. In this case, you might want to schedule all backups to be done as a cron job over night.


You can use a compression utility to reduce the amount of space required to store data. The amount of compression will depend on the nature of the data you're saving. Some databases containing large amounts of repetitive data may compress up to 90%. Other data might compress less than 10%.

Caution: Although compression saves media space, it has two undesirable side effects:
  • Compression requires a fair amount of computation and may slow down the process of saving the data.
  • You might not be able to recover compressed data if a defect develops during the process. Potentially, all data following a bad block in one part of the compressed data could affect the rest of the data.

You may use the gzip or freeze utilities to compress your data and the gunzip or melt utilities to restore it. Both utilities will act on a stream of data as well as on files. This ability to act as a filter lets you connect them to one of the standard archivers via a pipe. For example, we distribute the QNX operating system in compressed form on floppies using pax, freeze, and vol.

Archive examples

Compressed floppy archive

Collect files under /home into a tar format archive, compress the archive, and then write it out to as many floppies as are needed, adding sequence numbers to the diskettes:

pax -w -x ustar /home | freeze | vol -w /dev/fd0

Read data off floppies, decompress it, and restore the files:

vol -r /dev/fd0 | melt | pax -r

UNIX-compatible floppy archive

Save files under /home/dino in a tar format archive for restoration on a UNIX system:

pax -w -t/dev/fd0 -xustar /home/dino

Save files under /home/dino in a cpio format archive for restoration on a UNIX system:

pax -w -xcpio -t/dev/fd0 /home/dino

Restore data in a tar or cpio format archive from another UNIX system and place all files under /usr/unix:

pax -r -s -t/dev/fd0  ",/,/usr/unix/,"

Tape archive

Start a new tape archive and save all files to tape:

tape rewind erase
pax -w -t/dev/tp0 /

Append files that have changed since the date of the file lastsave to the end of an existing archive tape. After the save, update the time of lastsave:

tape forward
touch newsave
find / -newer lastsave | pax -w -t/dev/tp0
mv newsave lastsave

Restore all the files on a tape under the directory /home/dino:

tape rewind
pax -r "/home/dino/*" -t/dev/tp0


Copy all files from the filesystem on node 1 to the filesystem on node 2:

cp -Rp //1/ //2/

In the following example, the disk on node 2 is a very large optical. A full backup is done each Friday and a partial backup of modified files could be done each day of the week:

cp -Rp //1/ //2/fri
cp -Rp -a date //1/ //2/mon
cp -Rp -a date //1/ //2/tue

You can also do this with cpio -p.

[Previous] [Contents] [Index] [Next]