\begin{exe} {Using cpio for Backup}

   We are going to do essentially the same exercise now,
   but using \textbf{cpio} in place of \textbf{tar}.  We'll
   repeat the slightly altered instructions for ease of use.

   \begin{enumerate}
      \item
      Create a directory called \verb?backup? and in it
      place a compressed \textbf{cpio} archive of all the
      files under \filelink{/usr/include}, with the highest
      level directory being \verb?include?.  You can use
      any compression method (\textbf{gzip}, \textbf{bzip2}
      or \textbf{xzip}).
      \item
      List the files in the archive.
      \item
      Create a directory called \verb?restore? and
      unpack and decompress the archive.
      \item
      Compare the
      contents with the original directory the archive
      was made from.
   \end{enumerate}

   \begin{sol}

      \begin{enumerate}
         \item
         \begin{cmd}
$ (cd /usr ; find include | cpio -c -o > /home/student/backup/include.cpio)
         \end{cmd}
         \begin{response}
82318 blocks
         \end{response}
         or to put it in a compressed form:
         \begin{cmd}
$ (cd /usr ; find include | cpio -c -o | gzip -c > /home/student/backup/include.cpio.gz)
         \end{cmd}
         \begin{response}
82318 blocks
         \end{response}
         \begin{cmd}
$ ls -lh include*
         \end{cmd}
         \begin{response}
total 64M
-rw-rw-r-- 1 coop coop  41M Nov  3 15:26 include.cpio
-rw-rw-r-- 1 coop coop 6.7M Nov  3 15:28 include.cpio.gz
-rw-rw-r-- 1 coop coop 5.3M Nov  3 14:44 include.tar.bz2
-rw-rw-r-- 1 coop coop 6.8M Nov  3 14:44 include.tar.gz
-rw-rw-r-- 1 coop coop 4.7M Nov  3 14:46 include.tar.xz
         \end{response}
         \item
         \begin{cmd}
$ cpio -ivt < include.cpio
         \end{cmd}
         \begin{response}
drwxr-xr-x  86 root     root            0 Oct 29 07:04 include
-rw-r--r--   1 root     root        42780 Aug 26 12:24 include/unistd.h
-rw-r--r--   1 root     root          957 Aug 26 12:24 include/re_comp.h
-rw-r--r--   1 root     root        22096 Aug 26 12:24 include/regex.h
.....
         \end{response}
         Note the redirection of input; the archive is not an argument.
         One could also do:
         \begin{cmd}
$ cd ../restore
$ cat ../backup/include.cpio | cpio -ivt
$ gunzip -c include.cpio.gz | cpio -ivt
         \end{cmd}
         \item
         \begin{cmd}
$ rm -rf include
$ cpio -id < ../backup/include.cpio
$ ls -lR include
         \end{cmd}
         or
         \begin{cmd}
$ cpio -idv < ../backup/include.cpio

$ diff -qr include /usr/include
         \end{cmd}
      \end{enumerate}
   \end{sol}
\end{exe}

