55187 Linux Backup lab by David Papkin

This page by David Papkin is about Backup methods using Linux in course 55187

This lab is reproduced from linuxfoundation.org , used for 55187  LFS301 Linux course reference.only. V 5.0 c Copyright Linux Foundation 2017. All rights reserved.

Exercise 19.1: Using tar for Backup
1. Create a directory called backup and in it place a compressed tar archive of all the files under /usr/include, with the
highest level directory being include. You can use any compression method (gzip, bzip2 or xzip).
2. List the files in the archive.
3. Create a directory called restore and unpack and decompress the archive.
4. Compare the contents with the original directory the archive was made from.
Solution 19.1
1. $ mkdir /tmp/backup
$ cd /usr ; tar zcvf /tmp/backup/include.tar.gz include
$ cd /usr ; tar jcvf /tmp/backup/include.tar.bz2 include
$ cd /usr ; tar Jcvf /tmp/backup/include.tar.xz include

Notice the efficacy of the compression between the three methods:
$ du -sh /usr/include
55M /usr/include
2.

$ cd /tmp/backup

$ ls -lh include.tar.*

c7:/tmp/backup>ls -lh
total 17M
-rw-rw-r– 1 coop coop 5.3M Jul 18 08:17 include.tar.bz2
-rw-rw-r– 1 coop coop 6.7M Jul 18 08:16 include.tar.gz
-rw-rw-r– 1 coop coop 4.5M Jul 18 08:18 include.tar.xz
c7:/tmp/backup>
3. $ tar tvf include.tar.xz

qdrwxr-xr-x root/root
-rw-r–r– root/root
-rw-r–r– root/root
-rw-r–r– root/root
-rw-r–r– root/root
…..
0 2014-10-29 07:04 include/
42780 2014-08-26 12:24 include/unistd.h
957 2014-08-26 12:24 include/re_comp.h
22096 2014-08-26 12:24 include/regex.h
7154 2014-08-26 12:25 include/link.h

Note it is not necessary to give the j, J, or z option when decompressing; tar is smart enough to
figure out what is needed.
4. $ cd .. ; mkdir restore ; cd restore
$ tar xvf ../backup/include.tar.bz2
include/
include/unistd.h
include/re_comp.h
include/regex.h
include/link
…..
$ diff -qr include /usr/include
Exercise 19.2: Using cpio for Backup
We are going to do essentially the same exercise now, but using cpio in place of tar. We’ll repeat the slightly altered instructions for ease of use.
1. Create a directory called backup and in it place a compressed cpio archive of all the files under /usr/include, with
the highest level directory being include. You can use any compression method (gzip, bzip2 or xzip).
2. List the files in the archive.
3. Create a directory called restore and unpack and decompress the archive.
4. Compare the contents with the original directory the archive was made from.
Solution 19.2
1. $ (cd /usr ; find include | cpio -c -o > /home/student/backup/include.cpio)
82318 blocks
or to put it in a compressed form:
$ (cd /usr ; find include | cpio -c -o | gzip -c > /home/student/backup/include.cpio.gz)
82318 blocks
$ ls -lh include*
total 64M

-rw-rw-r– 1 coop coop 41M Nov 3 15:26 include.cpio
3 15:28 include.cpio.gz
3 14:44 include.tar.bz2
3 14:44 include.tar.gz
3 14:46 include.tar.xz
-rw-rw-r– 1 coop coop 6.7M Nov
-rw-rw-r– 1 coop coop 5.3M Nov
-rw-rw-r– 1 coop coop 6.8M Nov
-rw-rw-r– 1 coop coop 4.7M Nov

LFS301: V 5.0 c Copyright the Linux Foundation 2017. All rights reserved.
19.1. LABS 101
2. $ cpio -ivt < include.cpio

drwxr-xr-x
-rw-r–r–
-rw-r–r–
-rw-r–r–
…..
86 root
1 root
1 root
1 root
root
root
root
root
0 Oct 29 07:04 include
42780 Aug 26 12:24 include/unistd.h
957 Aug 26 12:24 include/re_comp.h
22096 Aug 26 12:24 include/regex.h

Note the redirection of input; the archive is not an argument. One could also do:
$ cd ../restore
$ cat ../backup/include.cpio | cpio -ivt
$ gunzip -c include.cpio.gz | cpio -ivt
3. $ rm -rf include
$ cpio -id < ../backup/include.cpio
$ ls -lR include
or
$ cpio -idv < ../backup/include.cpio
$ diff -qr include /usr/include

This page by David Papkin is about Backup methods using Linux in course 55187