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
- You need a backup of partitions and their metadata, as described in Section 5.4, “Backing up ext2, ext3, or ext4 File Systems”.
Procedure 5.2. Restoring ext2, ext3, or ext4 File Systems
- 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.
- Rebuild the partitions you want to restore by using the
fdiskorpartedutilites.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 thefdiskutility when backing up.For more information on modifying partitions, see Chapter 13, Partitions - Use the
mkfsutility to format the destination partition:mkfs.ext4 /dev/device
# mkfs.ext4 /dev/deviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Important
Do not format the partition that stores your backup files. - If you created new partitions, re-label all the partitions so they match their entries in the
/etc/fstabfile:e2label /dev/device label
# e2label /dev/device labelCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Create temporary mount points and mount the partitions on them:
mkdir /mnt/device mount -t ext4 /dev/device /mnt/device
# mkdir /mnt/device # mount -t ext4 /dev/device /mnt/deviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Restore the data from backup on the mounted partition:
cd /mnt/device restore -rf device-backup-file
# cd /mnt/device # restore -rf device-backup-fileCopy to Clipboard Copied! Toggle word wrap Toggle overflow 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 thesshutility. For more information onssh, 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-lesssshlogin, 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 -"
# ssh remote-address "cd /mnt/device && cat backup-file | /usr/sbin/restore -r -f -"Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 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"
# ssh remote-machine-1 "cd /mnt/device && RSH=/usr/bin/ssh /usr/sbin/restore -rf remote-machine-2:backup-file"Copy to Clipboard Copied! Toggle word wrap Toggle overflow
- Reboot:
systemctl reboot
# systemctl rebootCopy to Clipboard Copied! Toggle word wrap Toggle overflow
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”:
- Rebuild partitions you want to restore by using the
fdiskcommand. - Format the destination partitions:
mkfs.ext4 /dev/sda1 mkfs.ext4 /dev/sda2 mkfs.ext4 /dev/sda3
# mkfs.ext4 /dev/sda1 # mkfs.ext4 /dev/sda2 # mkfs.ext4 /dev/sda3Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Re-label all the partitions so they match the
/etc/fstabfile:e2label /dev/sda1 Boot1 e2label /dev/sda2 Root e2label /dev/sda3 Data
# e2label /dev/sda1 Boot1 # e2label /dev/sda2 Root # e2label /dev/sda3 DataCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Prepare the working directories.Mount the new partitions:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Mount the partition that contains backup files:mkdir /backup-files mount -t ext4 /dev/sda6 /backup-files
# mkdir /backup-files # mount -t ext4 /dev/sda6 /backup-filesCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Restore the data from backup to the mounted partitions:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Reboot:
systemctl reboot
# systemctl rebootCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional Resources
- For more information, see the restore(8) man page.