restore Command in Linux



The restore command in Linux is a critical utility designed for data recovery from backup archives, especially those created using the dump command. When you create backups of your filesystem to safeguard against data loss, restore becomes your go-to tool for retrieving that data.

The restore command is a vital tool for sysadmins and individuals tasked with retrieving lost files or entire file systems following unintended deletions, hardware malfunctions, or any unexpected events that jeopardize data integrity.

Table of Contents

Here is a comprehensive guide to the options available with the restore command −

Installing of restore Command

The command restore is typically included with the dump package in most Linux distributions. However, if it is not already installed on your system, you can easily install it using your distribution's package manager. Here are the steps to install the restore command on various Linux systems −

Debian-based Systems (e.g., Ubuntu, Debian)

sudo apt install dump

Red Hat-based Systems (e.g., CentOS, Fedora, RHEL)

sudo yum install dump

Arch-based Systems (e.g., Arch Linux, Manjaro)

sudo pacman -S dump

openSUSE

sudo zypper install dump

Syntax of restore Command

Here’s how you use the restore command −

1. Continue an Interrupted Restore

restore -C [-cdHklMvVy] [-b blocksize] [-D filesystem] [-f file] [-F script] [-L limit] [-s fileno] [-T directory]

2. Interactive Mode

restore -i [-acdhHklmMNouvVy] [-A file] [-b blocksize] [-f file] [-F script] [-Q file] [-s fileno] [-T directory]

3. Specify File with List of Files to Extract

restore -P file [-acdhHklmMNuvVy] [-b blocksize] [-f file] [-F script] [-s fileno] [-T directory] [-X filelist] [ file ... ]

4. Recover the Entire Filesystem

restore -R [-cdHklMNuvVy] [-b blocksize] [-f file] [-F script] [-s fileno] [-T directory]

5. Recover the Entire Filesystem

restore -R [-cdHklMNuvVy] [-b blocksize] [-f file] [-F script] [-s fileno] [-T directory]

6. Restore Everything from Backup

restore -r [-cdHklMNuvVy] [-b blocksize] [-f file] [-F script] [-s fileno] [-T directory]

7. List Backup Contents

restore -t [-cdhHklMNuvVy] [-A file] [-b blocksize] [-f file] [-F script] [-Q file] [-s fileno] [-T directory] [-X filelist] [ file ... ]

8. Extract Specific Files or Directories

restore -x [-adchHklmMNouvVy] [-A file] [-b blocksize] [-f file] [-F script] [-Q file] [-s fileno] [-T directory] [-X filelist] [ file ... ]

restore Command Options

Here are several useful options you can use with restore

Option Description
-C Compares files from a backup with the current disk contents.
-i Interactive mode for restoring files from a backup with a shell-like interface.
-P file Creates a new Quick File Access file from an existing dump without restoring.
-R Requests a specific tape from a multi-volume set to resume a full restore.
-r Rebuilds the file system by restoring a complete backup.
-t Lists names of specified files from the backup; lists entire content if no files are specified.
-x Extracts specified files from the media; directories are recursively extracted unless -h is used.
-a Disables volume prompts and reads all volumes starting with 1 for unattended extraction.
-A archive_file Reads table of contents from archive_file instead of media; used with -t, -i, or -x options.
-b blocksize Specifies kilobytes per dump record; defaults to dynamic determination if not set.
-c Disables dynamic format checking, only reads old format dumps.
-d Prints debug information.
-D system Specifies filesystem name when using -C to check backup.
-f file Reads backup from specified file, device, or standard input; supports remote files.
-F script Runs a script at the beginning of each tape; controls tape change prompts.
-h Extracts actual directory, not contents; prevents recursive restoration of subtrees.
-H hash_size Uses hashtable for directory entries to speed up inode lookups; uses more memory.
-k Uses Kerberos authentication for remote tape server connections (if enabled).
-I Assumes remote file is regular file for remote restores; required for remote compressed files.
-L limit Sets maximal miscompares for -C mode; defaults to 0 (no check).
-m Extracts files by inode numbers rather than file names.
-N Performs full execution without writing files to disk.
-o Automatically restores current directory permissions without confirmation in -i or -x modes.
-Q file Uses specified file to read tape positions stored with Quick File Access mode.
-s fileno Reads from specified fileno on a multi-file tape; numbering starts at 1.
-T directory Specifies directory for storing temporary files; default is /tmp.
-u Removes old entries before creating new ones to prevent warnings for existing files.
-v Enables verbose mode, printing name and type of each processed file.
-V Supports reading multi-volume non-tape media like CD-ROMs.
-X filelist Reads list of files from filelist in addition to command-line arguments for -t or -x.
-y Suppresses user prompts to abort restore in case of errors.

Examples of restore Command in Linux

Let’s explore a few practical examples of the Linux restore command −

  • Resuming an Interrupted Restore
  • Navigating an Interactive Restore
  • Creating a Quick Access File
  • Entire Filesystem Recovery
  • Listing Contents of a Backup

Resuming an Interrupted Restore

Imagine you have an interrupted restore process due to an unexpected shutdown. To continue from where it left off, use −

sudo restore -C -f backup.dump -s 2 -T /tmp

This command resumes the restore from the specified file (backup.dump), starting at the given fileno (2), and uses /tmp for temporary file storage.

Navigating an Interactive Restore

Suppose you need to selectively restore files from a backup. You can do this interactively by −

sudo restore -i -f backup.dump

Entering this command starts an interactive session where you can move around the directory tree and choose specific files to extract.

restore Command in Linux1

Creating a Quick Access File

If you want to speed up future restorations without extracting data right now, you can create a Quick File Access file −

sudo restore -P qfa_file -f backup.dump

This creates a Quick File Access file named qfa_file from the backup backup.dump, which helps in faster access next time.

restore Command in Linux2

Entire Filesystem Recovery

In case of a critical failure where the entire filesystem needs recovery, perform this by −

sudo restore -R -f backup.dump

This command will prompt for the necessary tapes and proceed to recover the entire filesystem from backup.dump.

Listing Contents of a Backup

To check what files are available in a backup without extracting them, you might use −

sudo restore -t -f backup.dump

Running this will list the names of all files in the backup.dump. If no specific files are mentioned, it will list the entire backup's contents.

restore Command in Linux3

Conclusion

The restore in Linux is a critical tool for data recovery from backups, especially those created using the dump command. By mastering its various modes and options, you can efficiently recover lost files or entire file systems following unintended deletions, hardware malfunctions, or other unexpected events.

Whether you need to continue an interrupted restore, interactively select files for extraction, or perform a complete file system recovery, the restore command provides the functionality you need.

Advertisements