Backup and Restore Files with CPIO in Linux

Learn On Demand
Learn On Demand Pro Series

This “Backup and Restore Files with CPIO in Linux” IT Pro Challenge virtual lab teaches you how to backup and restore files in Linux. You will learn how to use the cpio command to create archives and extract files from these archives. You will also learn how to archive and move an entire file system. By the end of this lab, you will have learned...

Time
45 minutes
Difficulty
Beginner
Share
Join over 3 million cybersecurity professionals advancing their career
Sign up with
or

Already have an account? Sign In »

Overview

The learning objective of this virtual lab is to show learners how to protect their data on Linux through file archiving on the Linux command line. This lab introduces them to the “cpio” command. Cpio, which stands for “copy in, copy out,” is both a Linux command and a file format. The cpio command creates a cpio archive. The cpio archive is a sequence of files and directories concatenated into a single archive with metadata about each file.

Understand the scenario: You are a Linux systems administrator responsible for a file server. You will use the cpio utility to back up and restore files.

Understand the environment: You will use a default installation of CentOS 7 Linux with the Server with GUI package installed. Non-privileged accounts will be created for you.

Back up files using cpio:

To backup and compress files, you will:

  • Use the command line to create several working files and directories and a Backups/ directory.
  • Use cpio to create a backup archive of these files.
  • Store the archive in the Backups/ directory.

Restore files using cpio:

To restore your files, you will:

  • Delete all of the original files you created.
  • Use cpio to restore the files from backup.

Move a files system using cpio:

You will archive an entire file systems using cpio and move this file system to a new directory by:

  • Using cpio and the list command to archive an entire file system..
  • Copying the file directory archive to a new directory.
  • Using cpio to restore the file system from archive into the new file directory.

Summary:

After completing the “Back Up and Restore Files with CPIO in Linux” challenge, you will have accomplished the following:

  • Archived files using cpio.
  • Restored files from the archive.
  • Archived an entire file system using cpio.
  • Moved the file system archive to a new file system.
  • Restored the file system from the archive.

Some of the benefits of cpio over other file archivers are:

  • Cpio is available in almost all Linux distributions.
  • Cpio provides a single command for both backing up and restoring files.
  • Cpio has the option to archive files into 8 different archive formats, including tar.
  • Cpio accepts a list of files as input and provides more command line options to programmatically process files.

Additionally, cpio archives offer many unique advantages over other file archives that make it ideal for system backup and restore, such as:

  • Cpio can duplicate a directory tree, preserving file ownership, modes, and access times.
  • Cpio skips damaged files during restoration and does not stop when it encounters corrupt data.
  • Cpio has a “pass through” mode that allows users to move entire directory trees/file systems.

Other Challenges in this series

  • GUIDED CHALLENGE: Linking Files in Linux
  • ADVANCED CHALLENGE: Can You Configure ACL Permissions in Linux?