Q4. Backup and Restore Using cpio and find Commands, output redirection operator
ID: 3836914 • Letter: Q
Question
Q4. Backup and Restore Using cpio and find Commands, output redirection operator > and input redirection operator <. The minimum cpio options you must know are d, i, o, and v.
Make your login directory as your working directory
Using the find command and the cpio command, create a backup file called backup containing all the files in your login directory. To do backup, pipe the standard output of the find command to the cpio command and redirect the cpio standard output to the file named, backup like find . | cpio options > backup. Use appropriate options in the place of options in the cpio command to do backup. Do not type the word “option”. Must use verbose option in addition to other required options so that the list of files being backed will be displayed on the monitor. Make sure you use relative path in the find command to generate the list of files with relative path; otherwise you will not be able to restore the files in the restore directory.
Display the attributes of the backup file
Create the directory restore under your login directory
Copy the backup file from your login directory to the restore directory
Change working directory to restore
Issue pwd command
Display the attributes of the files in the restore directory
Restore the files from the backup file into the restore directory. Redirect input using < operator from backup file to the cpio command. Must use verbose option and create directory option in addition to other required options so that the list of files being restored will be displayed on the monitor and subdirectories will be created.
Display the attributes of the files restored files in the restore directory
Explanation / Answer
From the login directory run the below commands to do the job
### find . lists the files in current dir and cpio will make a backup out of all these files
### -v is for verbose and -o is for running cpio in copy-outmode
find . | cpio -vo > backup
ls -l backup ###for listing attributes of backup file
mkdir restore ##for creating restore dir
cp backup restore/ ###copying backup file under restore dir
cd restore/ ### For changingworking directory to restore
pwd
ls -l ### For displaying the attributes of the files
##For restoring files from backup file, -i for running cpio in copy-in mode and -d for creating required directories
cpio -idv < backup
ls -l
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.