Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

5.5. Restoring ext2, ext3, or ext4 File Systems

This procedure describes how to restore an ext4, ext3, or ext2 file system from a file backup.

Prerequisites

Procedure 5.2. Restoring ext2, ext3, or ext4 File Systems

  1. If you are restoring an operating system partition, boot your system into Rescue Mode. See the Booting to Rescue Mode section of the System Administrator's Guide.
    This step is not required for ordinary data partitions.
  2. Rebuild the partitions you want to restore by using the fdisk or parted utilites.
    If the partitions no longer exist, recreate them. The new partitions must be large enough to contain the restored data. It is important to get the start and end numbers right; these are the starting and ending sector numbers of the partitions obtained from the fdisk utility when backing up.
    For more information on modifying partitions, see Chapter 13, Partitions
  3. Use the mkfs utility to format the destination partition:
    # mkfs.ext4 /dev/device

    Important

    Do not format the partition that stores your backup files.
  4. If you created new partitions, re-label all the partitions so they match their entries in the /etc/fstab file:
    # e2label /dev/device label
  5. Create temporary mount points and mount the partitions on them:
    # mkdir /mnt/device
    # mount -t ext4 /dev/device /mnt/device
  6. Restore the data from backup on the mounted partition:
    # cd /mnt/device
    # restore -rf device-backup-file
    If you want to restore on a remote machine or restore from a backup file that is stored on a remote host, you can use the ssh utility. For more information on ssh, see the Using the ssh Utility section of the System Administrator's Guide.
    Note that you need to configure a password-less login for the following commands. For more information on setting up a password-less ssh login, see the Using Key-based Authentication section of the System Administrator's Guide.
    • To restore a partition on a remote machine from a backup file stored on the same machine:
      # ssh remote-address "cd /mnt/device && cat backup-file | /usr/sbin/restore -r -f -"
    • To restore a partition on a remote machine from a backup file stored on a different remote machine:
      # ssh remote-machine-1 "cd /mnt/device && RSH=/usr/bin/ssh /usr/sbin/restore -rf remote-machine-2:backup-file"
  7. Reboot:
    # systemctl reboot

Example 5.4. Restoring Multiple ext4 Partitions

To restore the /dev/sda1, /dev/sda2, and /dev/sda3 partitions from Example 5.2, “Backing up Multiple ext4 Partitions”:
  1. Rebuild partitions you want to restore by using the fdisk command.
  2. Format the destination partitions:
    # mkfs.ext4 /dev/sda1
    # mkfs.ext4 /dev/sda2
    # mkfs.ext4 /dev/sda3
  3. Re-label all the partitions so they match the /etc/fstab file:
    # e2label /dev/sda1 Boot1
    # e2label /dev/sda2 Root
    # e2label /dev/sda3 Data
  4. Prepare the working directories.
    Mount the new partitions:
    # mkdir /mnt/sda1
    # mount -t ext4 /dev/sda1 /mnt/sda1
    # mkdir /mnt/sda2
    # mount -t ext4 /dev/sda2 /mnt/sda2
    # mkdir /mnt/sda3
    # mount -t ext4 /dev/sda3 /mnt/sda3
    Mount the partition that contains backup files:
    # mkdir /backup-files
    # mount -t ext4 /dev/sda6 /backup-files
  5. Restore the data from backup to the mounted partitions:
    # cd /mnt/sda1
    # restore -rf /backup-files/sda1.dump
    # cd /mnt/sda2
    # restore -rf /backup-files/sda2.dump
    # cd /mnt/sda3
    # restore -rf /backup-files/sda3.dump
  6. Reboot:
    # systemctl reboot

Additional Resources

  • For more information, see the restore(8) man page.