[ Team LiB ] Previous Section Next Section

Backing Up and Restoring File Systems

Backing up files means making copies of them, usually on removable media, as a safeguard in case the originals get lost or damaged. Backup tapes are convenient for restoring accidentally deleted files, but they are essential in case of serious hardware failures or other disasters.

Backing up files is one of the most crucial system administration functions. You must plan and carry out a procedure for regularly scheduled backups of your file systems for three major reasons.

  • To ensure file system integrity against a possible system crash.

  • To protect user files against accidental deletion.

  • To act as an important safeguard before reinstalling or upgrading a system.

When you back up file systems as scheduled, you have the assurance that you can restore any files to a reasonably recent state. In addition, you may want to back up file systems to transport them from one system to another or to archive them—saving files on a transportable medium—so that you can remove or alter the files that remain on the system.

When you plan a backup schedule, you need to consider the following factors.

  • Which command to use to back up the file systems.

  • What medium to use.

  • What backup schedule to use.

  • Which file systems to back up.

  • Which files are critical to users on this system.

  • Where the files are located—are they in a single file system?

  • How often these files change.

  • How quickly you would need to restore these files in the event of damage or loss.

  • How often the relevant file systems can be unmounted so that they are available for backup.

Outlining possible backup strategies is beyond the scope of this book. See the ufsdump(1M) manual page for a suggested dump schedule. The discussions that follow describe how to use the ufsdump command to make backups and how to retrieve files with the ufsrestore command.

Table 50 lists the commands that you can use to back up and restore individual files and file systems.

Table 50. Commands for Backing Up and Restoring Files and File Systems



Back up complete or individual file systems to a local or remote tape device.


Restore complete or individual file systems to a local disk.


Specifying Tape Characteristics

The ufsdump command uses a set of defaults when you do not specify any tape characteristics. Note that you can specify the options in any order as long as the arguments that follow match the order of the options.

Specifying a Backup Level


You can specify a numerical argument to ufsdump from 0 to 9 to designate the level of the backup to be performed. A level 0 dump backs up all of the files in the file systems you specify. All files that have been modified since the last ufsdump at a lower dump level are copied to the dump file destination. For example, if a level 2 dump was done on Monday, followed by a level 4 dump on Tuesday, a subsequent level 3 dump on Wednesday would contain all files modified or added since the level 2 (Monday) backup.

Backing Up a File System with Cartridge Tapes (ufsdump)

To do a full backup on a file system, be sure all users are logged out. Then bring the system to single-user mode. (See "Tape Device–Naming Conventions" on page 241 if you need information about tape device names.)

You can dump or restore files from a remote drive by adding remote-host: to the front of the tape device name with the following syntax.


For example, the device name for a remote tape drive /dev/rmt/0, on the system oak, would be oak:/dev/rmt/0.

Use the following steps to do a level 0 (full) backup of a file system.

  1. Type telinit s and press Return. The system is brought to single-user mode, which ensures that no users can change the file systems you are backing up.

  2. Insert a tape cartridge in the QIC-150 tape drive.

  3. Type ufsdump 0cuf /dev/rmt/ unit cntndns[[0-7] andpress Return.

    The 0 option specifies a level 0 (complete) dump. The c option specifies cartridge tape. The u option updates the dump record. The f option followed by the device name specifies the device file. Type the raw disk slice for the file system you want to back up, for example, c0t0d0s7 for /files1.

    The following example does a level 0 dump of the c0t0d0s7 slice.

    oak% su
    # telinit s
    # ufsdump 0cuf /dev/rmt/0 c0t0d0s7
      DUMP: Date of this level 0 dump: Wed Mar 11 10:16:53 1992
      DUMP: Date of last level 0 dump: the epoch
      DUMP: Dumping /dev/rdsk/c0t3d0s7 (/export/home) to /dev/rmt/0
      DUMP: mapping (Pass I) [regular files]
      DUMP: mapping (Pass II) [directories]
      DUMP: estimated 956 blocks (478KB)
      DUMP: Writing 63 Kilobyte records
      DUMP: dumping (Pass III) [directories]
      DUMP: dumping (Pass IV) [regular files]
      DUMP: level 0 dump on Wed Mar 11 10:16:53 1992
      DUMP: 956 blocks (478KB) on 1 volume
  4. If the dump requires more than one tape, the ufsdump command tells you when to change to a new tape.

  5. Label the tape with the command, file system, and date so that you can easily find the backup tape if you need to restore files.

Performing Incremental Backups

You can specify different backup levels with the ufsdump command, making it possible to back up only those files that were changed since a previous backup at a lower level. Use the following steps to back up incremental changes since the last complete dump.

  1. Bring the system to single-user mode.

  2. Become superuser.

  3. Put a tape into the tape drive.

  4. All on one line, type ufsdump [1-9] ucf /dev/rmt/ unit /dev/rdsk/cntndnsn and press Return. Type the level of the backup at the beginning of the ufsdump arguments. For example, for a level 9 backup, type 9ucf as the first argument.

  5. Remove the tape from the tape drive and label it. If you put multiple backups on the same tape, be sure you add each incremental backup to the label of the tape.

Restoring a Backed-Up File System (ufsrestore)

The ufsrestore command copies files from backups created by the ufsdump command into the current working directory. You can use ufsrestore to reload an entire file system hierarchy from a level 0 dump and incremental dumps that follow it or to restore one or more single files from any dump tape. Files are restored with their original owner, last modification time, and mode (permissions).

Before you start to restore files or file systems, you need the following information.

  • Which tapes you need.

  • The raw device name for the file systems you want to restore.

  • The device name (local or remote) for the tape drive.

Determining Which Tapes to Use

Before you can begin restoring file systems or files, you must determine which backup tapes you need. When restoring an entire file system, you always need the most recent level 0 backup tape. You also need the most recent incremental backup tapes made at each of the higher levels. Refer to the backup plan that you are using to determine the levels and number of tapes you need. For example, if you make level 0 and level 9 backups, you need the most recent level 0 and level 9 backup tapes.

Use the following steps to determine which tapes to use to restore individual files or file systems.

  1. Ask the user the date when the file or file system was lost or the approximate date of the files to be recovered.

  2. Refer to your backup plan to find the date of the last backup that would have the file or file system on it.

    Note that you do not necessarily use the most recently backed up version of the file. To retrieve the most recent version of a file, work backward through the incremental backups from highest to lowest level and most recent to least recent.

  3. If you have on-line archive files created by the ufsdump -a option, type ufsrestore ta archive-name / path/ filename(s) and press Return. Be sure to use the complete path for the filename(s).

    A list of the files and the media they are stored on is displayed.

  4. Retrieve the media containing the backups.

    Be aware of the storage organization of backup media at your site so that you can locate media that are months or years old.

  5. Insert media in the drive and type ufsrestore tf device-name /path/filename(s) and press Return. Be sure to use the complete path for the filename(s).

    If a file is in the backup, its name and inode number are listed. Otherwise, a message says it is not on the volume.

  6. If you have multiple dump files on the same tape, you can use the -s n option to position the tape at the dump you want to use.

    For example, type ufsrestore xfs /dev/rmt0 5 and press Return to position the tape at the fifth dump and restore it.

Restoring a Full Backup

Use the following steps to restore a full backup of a file system on a cartridge tape.

CAUTION. This procedure completely destroys any data already in the file system by overwriting any files or directories under the directory to which you tell ufsrestore to restore.

  1. Become superuser.

  2. Type telinit s and press Return.

    The system is brought to single-user mode, which ensures that no one is using the file system you are restoring.

  3. Type umount mount-point and press Return.

    The mount point you specify (for example, /files1) is unmounted.

  4. Type newfs /dev/rdsk/cntndnsnandpress Return.

    The raw device file for the disk slice (for example, /dev/rdsk/c0t0d0s7 for the /home slice) is wiped clean and the file system is rebuilt.

  5. Typemount /dev/dsk/cntndnsnandpress Return.

    The file system, specified as the block file device (for example, /dev/dsk/c0t0d0s7 for /files1), is remounted at the mount point you specify.

  6. Type cd mount-point and press Return.

    Focus is in the directory you want to restore.

  7. Insert the tape cartridge in the QIC-150 tape drive.

  8. Type ufsrestore rvf /dev/rmt/0h and press Return.

    The h option extracts the actual directory instead of the files that it references. This option prevents hierarchical restoration of complete subtrees from the tape. The file system is restored.

    In the following example, the /files1 slice c0t0d0s7 is restored.

oak% su
# telinit s
# umount /files1
# newfs /dev/rdsk/c0t0d0s7
# mount /dev/dsk/c0t0d0s7 /files1
# cd /files1
# ufsrestore rvf /dev/rmt/0h

Restoring Files Interactively

When restoring individual files and directories, it is a good idea to restore them to a temporary directory such as /var/tmp. After you verify them, you can move the files to their proper locations. You can restore individual files and directories to their original locations. If you do so, be sure you are not overwriting newer files with older versions from the backup tape.

Use the following steps to restore files interactively.

  1. Become superuser.

  2. Write-protect the tape for safety.

  3. Put the backup tape in the tape drive.

  4. Type cd /var/tmp and press Return.

    If you want to restore the files to a different directory, substitute the directory name for /var/tmp in this step.

  5. Type ufsrestore if /dev/rmt/ unit and press Return.

    Some informational messages and the restore> prompt are displayed.

  6. Create a list of files to be restored.

    • To list the contents of a directory, type ls and press Return.

    • To change directories, type cd directory-name and press Return.

    • To add a directory or file name to the list of files to be restored, type add filename and press Return.

    • To remove a directory or file name from the list of files to be restored, type delete filename and press Return.

    • To keep the mode of the current directory unchanged, type setmodes and press Return. Then type n and press Return.

  7. When the list is complete, type extract and press Return. Then, ufsrestore asks you which volume number to use.

  8. Type the volume number and press Return. If you have only one volume, type 1 and press Return.

    The files and directories in the list are extracted and restored to the current working directory.

  9. Type quit and press Return.

    The shell prompt is displayed.

  10. Use the ls -l command to list the restored files and directories.

    A list of files and directories is displayed.

  11. Check the list to be sure all the files and directories you specified in the list have been restored.

  12. Use the mv command to move the files to the proper directories.

The following example restores the files backup.examples and junk from the pubs directory.

# cd /var/tmp
# ufsrestore if /dev/rmt/0
ufsrestore > ls
 lost+found/  pubs/

ufsrestore > cd pubs
ufsrestore > ls
 .Xauthority         .login                      .profile                backup.examples%
 .Xdefaults          .mtdeletelog                .wastebasket/           core
 .cshrc              .openwin-init               Junk/                   dead.letter
 .desksetdefaults    .openwin-init.BAK           backup.examples         junk

ufsrestore > add backup.examples
ufsrestore > add junk
ufsrestore > setmodes
set owner/mode for '.'? [yn] n
ufsrestore > extract
You have not read any volumes yet.
Unless you know which volume your file(s) are on you should start
with the last volume and work towards the first.
Specify next volume #: 1
set owner/mode for '.'? [yn] n
ufsrestore > quit
# ls -l
total 6
drwxrwxrwt    3 sys        sys          512 Mar 11 10:36 ./
drwxrwxr-x   18 root       sys          512 Mar 10 16:43 ../
drwxr-xr-x    2 pubs       staff        512 Mar 11 10:11 pubs/
# pwd
# cd pubs
# ls
./               ../                  backup.examples junk

Restoring a Single File from a Backup Tape (ufsrestore)

Use the following steps to restore a single file from a backup tape.

  1. Become superuser.

  2. Put the backup tape in the tape drive.

  3. Type cd /var/tmp and press Return.

    If you want to restore the files to a different directory, substitute the directory name for /var/tmp in this step.

  4. Type ufsrestore xf /dev/rmt/ unit /pathto/filename and press Return.

    The x option tells ufsrestore to copy specific files or directories in the /pathto/filename argument. The message set owner/mode for '.'? [yn] is displayed.

  5. Type n and press Return.

    Directory modes remain unchanged.

  6. Type the volume number where files are located and press Return. If there is only one volume, type 1 and press Return.

    The file is restored to the current working directory.

  7. Type ls -l filename and press Return.

    A listing for the file is displayed.

  8. Use the mv command to move the file to the proper directory.

Creating a Snapshot of a UFS File System


You can use the fssnap(1M) command, new in the Solaris 9 release, to create a read-only snapshot of a file system. You can use the snapshot to back up file systems while the file system is mounted.

When you run the fssnap command, it creates a virtual device and a backing-store file. You can use any of the existing Solaris backup commands to back up the virtual device, which looks and acts like a real device. The backing-store is a bitmapped file that contains copies of presnapshot data that has been modified since the snapshot was taken.

With UFS snapshots, you can keep the file system mounted and the system in multiuser mode while performing system backups. In previous releases, you were advised to bring the system to single-user mode to keep the file system inactive while using the ufsdump command to back up file systems.

UFS snapshots are similar to the Instant Image process. Instant Image allocates space equal to the size of the entire file system being captured. The UFS snapshot backing-store file occupies only as much disk space as needed and you can place a maximum size on the backing-store file.

NOTE. Although you can use UFS snapshots to make copies of large file systems, it is better suited for smaller systems. Instant Image is better suited for enterprise-level systems.

When you first create the UFS snapshot, users of the file system might notice a slight pause. The length of the pause increases with the size of the file system being captured. While the snapshot is active, users of the file system may notice a slight performance impact when writing to the file system but will notice no impact when the file system is read.

Syntax and Options of the fssnap Command

The syntax of the fssnap command is shown below.

/usr/sbin/fssnap [-F FSType][-V] -o special_options[mount-point | special ]
/usr/sbin/fssnap -d [-F FSType] [-V] -o special_options [mount-point | special ]
/usr/sbin/fssnap -i [-F FSType] [-V] -o special_options [mount-point | special]

The options to the fssnap command are described in Table 51.

Table 51. Options to the fssnap Command




Delete the snapshot associated with the given file system.

-F FSType

Specify the file system type to be used. You can specify the FSType here, or fssnap determines it by matching the block special device with an entry in the /etc/vfstab table or by consulting /etc/default/fs.


Display the state of any given FSType snapshot. If you specify no mount-point or device, fssnap displays a list of all snapshots on the system. When you specify a mount-point or device, fssnap provides detailed information for the specified file system snapshot by default. The format and meaning of this information is file system dependent. See the FSType-specific fssnap manual page for details.

-o special_options


See the FSType-specific manual page for fssnap. The UFS special_options are listed below


backing-store= path


Use path as the backing-store file. path must not reside on the file system that is being captured in a snapshot. path must exist and must be either a directory or a regular file. If path is a directory, then a temporary file is created and held open. That device is then used as-is. You can abbreviate this option as bf= path or bs= path.



Unlink the backing-store file after the snapshot is created. This option specifies that the backing-store file does not need to be removed manually when the snapshot is deleted. This behavior might make administration more difficult because the file is not visible in the file system. If you do not specify this option, manually remove the backing-store files after the snapshot is deleted.


chunksize= n [k,m,g]


Use n to specify the granularity of the data that is sent to the backing-store. Specify chunksize in k for kilobytes, m for megabytes, or g for gigabytes. By default, chunk size is four times the block size of the file system (typically 32k).


maxsize= n[k,m,g]


Do not allow the size of the backing-store file to exceed n, where n is the specified unit. The snapshot is deleted automatically when the backing-store file exceeds maxsize. Specify maxsize in k for kilobytes, m for megabytes, or g for gigabytes.



Display to standard output the name of the raw device instead of the block device when a snapshot is created. The block device is printed by default (when you do not specify raw). This option makes it easier to embed fssnap commands in the command line for commands that require the raw device instead. Both devices are always created. This option affects only the output.


Echo the complete command line, but do not execute the command.

Creating a UFS Snapshot

When you use the fssnap command to create a UFS snapshot, observe how much disk space is consumed by the backing-store file. Make sure the backing-store file has enough space to grow, or limit its size with the -o maxsize= n [k,m,g] option.

Use the following steps to create a UFS snapshot.

  1. Become superuser or assume an equivalent role.

  2. Type df -h and press Return.

    Check the output to make sure that the file system has enough disk space for the backing-store file.

  3. Type ls / backing-store-file and press Return.

    Check to make sure that a backing-store file of the same name and location does not already exist.

  4. Type fssnap -F ufs -o bs=/ backing-store-file / file-system and press Return.

    The backing-store file must reside on a different file system from the file system for which you are making a snapshot.

  5. Type /usr/lib/fs/ufs/fssnap -i / file-system and press Return.

    Verify that the snapshot has been created.

The following example creates a snapshot of the root file system with a /home/winsor/rootbackup backing-store file.

mopoke% df -h
Filesystem            size   used   avail capacity   Mounted on
/dev/dsk/c1t0d0s0     4.3G   1.1G   3.2G     26%     /
/proc                 0K     0K     0K        0%     /proc
mnttab                0K     0K     0K        0%     /etc/mnttab
fd                    0K     0K     0K        0%     /dev/fd
swap                545M    40K   545M        1%     /var/run
swap                546M    304K  545M        1%     /tmp
/dev/dsk/c1t0d0s7   4.9G    1.1G  3.8G       22%     /export/home
/export/home/winsor 4.9G    1.1G  3.8G       22%     /home/winsor
mopoke% su
# fssnap -F ufs -o bs=/home/winsor/rootbackup
# fssnap -i
   0       /
# /usr/lib/fs/ufs/fssnap -i /
Snapshot number              : 0
Block Device                 : /dev/fssnap/0
Raw Device                   : /dev/rfssnap/0
Mount point                  : /
Device state                 : idle
Backing store path           : /home/winsor/rootbackup
Backing store size           : 1536 KB
Maximum backing store size   : Unlimited
Snapshot create time         : Mon Sep 30 15:36:11 2002
Copy-on-write granularity    : 32 KB

Deleting a UFS Snapshot

You can delete a snapshot either by rebooting the system or by using the fssnap -d command and specifying the path of the file system that contains the UFS snapshot.

Use the following steps to delete a UFS snapshot with the fssnap -d command.

  1. Become superuser or assume an equivalent role.

  2. Type fssnap -i and press Return.

    A list of available snapshots is displayed.

  3. Type fssnap -d / file-system and press Return.

    The snapshot is deleted.

  4. (Optional.) If you did not use the -o unlink option when you created the snapshot, you need to delete the backing-store file manually by typing rm /file-system/ backing-store-file and pressing Return.

The following example shows how to delete a snapshot and assumes that the unlink option was not used.

# fssnap -i
   0     /
# fssnap -d /
Deleted snapshot 0.
# ls /home/winsor/rootbackup
# rm /home/winsor/rootbackup

Backing Up a UFS Snapshot

You can create a full or incremental backup of a UFS snapshot and use the standard Solaris ufsdump command to back up a UFS snapshot. Simply specify the raw device name of the snapshot, for example, /dev/rfssnap/1, as the final argument to the ufsdump command.

Restoring Data from a UFS Snapshot Backup

Any backup you create from a virtual device is simply a backup of the state of the original file system when you took the snapshot. When you restore from the backup, restore with the ufsrestore command as if you had taken the backup directly from the original file system.

    [ Team LiB ] Previous Section Next Section