CIS 90

advertisement
CIS 90 - Lesson 14
Lesson Module Status
• Slides –
• Properties • Flash cards –
• No-stress quiz –
• Web calendar summary –
• Web book pages –
• Commands –
• Lab – done
• Supplies () • Class PC's –
• Scripts () –
CIS 90 - Lesson 14
Quiz
CIS 90 - Lesson 14
The UNIX/Linux File System
Objectives
Agenda
• Use conditionals in scripts
• Transfer files between computers
• Archive directories using tar
• No Quiz - warmup exercise instead
• Questions from last week
• scp
• More scripting
• Tarballs
• Wrap up
 = hands on exercise for topic
CIS 90 - Lesson 14
Previous material and assignment
1. Questions?
2. No labs due today
3. Check grades page
4. Check your class/labs/ directory on
Opus for graded work
CIS 90 - Lesson 14
Warmup Exercise
Find the hidden treasure trove
• Find the treasure buried in you Hidden folder.
• When you find it make sure only you can read it and
nobody can modify it.
CIS 90 - Lesson 14
scp
CIS 90 - Lesson 14
Classroom PC's, VMs and Remote Server
Opus
One RHEL5 server
per class
Internet
One RH9 Linux
VM per laptop
One Windows
laptop per student
SSH is a network
protocol that enables
secure connections
between computers
CIS 90 - Lesson 14
Telnet and SSH (Secure Shell)
Opus
SSH - encrypted
Telnet - all clear text
Sniffer view of a Telnet session
Sniffer view of a SSH session
username
password
cat secret
exit
Local computer
CIS 90 - Lesson 14
ssh protocol
Secure Shell Protocol
• Allows secure (encrypted connections between computers)
• ssh command – secure login and terminal sessions
• scp command – secure file copies between computers
/
CIS 90 - Lesson 14
scp
Copy commands copy file(s) to a Destination
• cp
‒ copies files on the same computer
‒ examples:
cp myscript myscript.v1
cp myscript.v1 backups/
cp /home/cis90/simmsben/bin/myscript benscript
• scp
‒ copies files between computers:
‒ examples:
scp roddyduk@opus.cabrillo.edu:myscript
.
/
scp lab45 roddyduk@opus.cabrillo.edu:lab45
scp lab45 roddyduk@opus.cabrillo.edu:
CIS 90 - Lesson 14
scp
command
1st argument
(from)
2nd argument
(to)
scp
roddyduk@opus.cabrillo.edu:bin/myscript
scp
lab45
roddyduk@opus.cabrillo.edu:lab45
scp
lab45
roddyduk@opus.cabrillo.edu:
.
CIS 90 - Lesson 14
scp
Remote
scp
roddyduk@opus.cabrillo.edu:bin/myscript
Copy the file myscript from roddyduk's home bin/ directory on
the remote system Opus to "here"
Local
.
CIS 90 - Lesson 14
scp
Remote
scp
Local
roddyduk@opus.cabrillo.edu:bin/myscript
.
Path to file. Relative to
user's home directory.
Either the IP address or hostname of the remote
computer. Need to connect to system on the Internet
The username on the remote computer. Needed to login and
this defines the home directory for the relative path to the file
CIS 90 - Lesson 14
scp
Logged in to two
different systems
Local Linux System
Opus
/
CIS 90 - Lesson 14
scp
Local Linux System
Performing scp copy
from Opus to local
Red hat system
Opus
/
CIS 90 - Lesson 14
scp
Catting files on both
systems to verify
the copy
Local Linux System
Opus
/
CIS 90 - Lesson 14
Class Exercise
scp
• Start up the local VM on the laptops and login as cisco
• Use Putty and login to your account on Opus
• Copy the files banner and myscript from your bin directory on Opus
scp logname@opus.cabrillo.edu:bin/myscript .
scp logname@opus.cabrillo.edu:bin/banner .
• Create a bin directory on your local VM (if needed)
mkdir bin
• Move banner and myscript to your local VM bin directory
mv banner myscript bin/
• Check path and permissions to make insure /home/cisco/bin is in your path and
that myscript and banner have execute permission set.
echo $PATH
ls –l /home/cisco/bin/
• Run the script you made on Opus on your local VM
myscript
CIS 90 - Lesson 14
To copy multiple files,
use the * expansion
character
Note, this will copy
files, but not
directories
CIS 90 - Lesson 14
To recursively copy
files and directories
use the –r option
Now all files and directories will be copied
CIS 90 - Lesson 14
Class Exercise
scp
• Copy all the files and directories in your Opus bin directory to your local bin
directory
scp –r logname@opus.cabrillo.edu:bin/* /home/cisco/bin/
• Now see if you can copy your entire poems directory on Opus to a new poems
directory in your local cisco home directory. When finished write the commands
you used on the whiteboard.
CIS 90 - Lesson 14
scripting
CIS 90 - Lesson 14
myscript
3)
# Commands for Task 3
;;
1)
2)
3)
4)
5)
6)
Duke's CIS 90 Final Project
Color
My Find Command
More practice
Duke's friend made this one - Thank You
Task 5
Exit
Enter Your Choice: 3
Hit the Enter key to return to menu
CIS 90 - Lesson 14
myscript
3)
# Commands for Task 3
date
;;
1)
2)
3)
4)
5)
6)
Duke's CIS 90 Final Project
Color
My Find Command
More practice
Duke's friend made this one - Thank You
Task 5
Exit
Enter Your Choice: 3
Wed Dec 3 14:07:07 PST 2008
Hit the Enter key to return to menu
CIS 90 - Lesson 14
myscript
3)
# Commands for Task 3
echo "Hello $LOGNAME"
date
;;
1)
2)
3)
4)
5)
6)
Duke's CIS 90 Final Project
Color
My Find Command
More practice
Duke's friend made this one - Thank You
Task 5
Exit
Enter Your Choice: 3
Hello roddyduk
Wed Dec 3 14:07:07 PST 2008
Hit the Enter key to return to menu
CIS 90 - Lesson 14
myscript
3)
# Commands for Task 3
echo "Hello $LOGNAME"
date
;;
1)
2)
3)
4)
Duke's CIS 90 Final Project
Color
My Find Command
More practice
Duke's friend made this one - Thank
You
5) Task 5
6) Exit
Enter Your Choice: 3
Hello roddyduk
Wed Dec 3 14:07:07 PST 2008
Hit the Enter key to return to menu
CIS 90 - Lesson 14
myscript
3)
# Commands for Task 3
echo "Hello $LOGNAME"
date
;;
1)
2)
3)
4)
5)
6)
Duke's CIS 90 Final Project
Color
My Find Command
More practice
Duke's friend made this one - Thank You
Task 5
Exit
Enter Your Choice: 3
Hello roddyduk
Wed Dec 3 14:07:07 PST 2008
Hit the Enter key to return to menu
CIS 90 - Lesson 14
myscript
3)
# Commands for Task 3
NAME=$(cat /etc/passwd | grep $LOGNAME | cut -f5 -d":" )
echo "Hello $NAME"
date
;;
1)
2)
3)
4)
5)
6)
Duke's CIS 90 Final Project
Color
My Find Command
More practice
Duke's friend made this one - Thank You
Task 5
Exit
Enter Your Choice: 3
Hello Duke Roddy
Wed Dec 3 14:07:07 PST 2008
Hit the Enter key to return to menu
CIS 90 - Lesson 14
Class Exercise
Scripting
• Make a short script that does the following:
• Get and displays the user's name
• Runs one command
CIS 90 - Lesson 14
myscript
3)
# Commands for Task 3
NAME=$(cat /etc/passwd | grep $LOGNAME | cut -f5 -d":" )
echo "Hello $NAME"
;;
1)
2)
3)
4)
5)
6)
Duke's CIS 90 Final Project
Color
My Find Command
More practice
Duke's friend made this one - Thank You
Task 5
Exit
Enter Your Choice: 3
Hello Duke Roddy
Hit the Enter key to return to menu
CIS 90 - Lesson 14
myscript
3)
# Commands for Task 3
NAME=$(cat /etc/passwd | grep $LOGNAME | cut -f5 -d":" )
echo "Hello $NAME"
date '+%A'
date '+%A, %B %d, %Y'
;;
Enter Your Choice: 3
Hello Duke Roddy
Hit the Enter key to return to menu
Enter Your Choice: 3
Hello Duke Roddy
Hit the Enter key to return to menu
CIS 90 - Lesson 14
Class Exercise
Scripting
• Modify your script to do the following:
• Ask the user a question
• Use a conditional (if statement) that users
the users response.
CIS 90 - Lesson 14
tar
CIS 90 - Lesson 14
tar command
options
(no – needed)
c
tar tvf
x
archive file
files to
backup
tarfile
file(s)
create
table of contents (view)
extract
v = verbose, double v (vv)
provides more information
Note: The full path to each file is stored in the
archive and these paths are used when restoring
files
CIS 90 - Lesson 14
tar command
Single file example
[root@benji ~]# cd /opt/lampp/htdocs/
[root@benji htdocs]# ls -l sample.html
-rw-r--r-- 1 root root 194 Oct 24 10:13 sample.html
[root@benji htdocs]# cat sample.html
<html>
<head>
<title>My first page</title>
</head>
<body>
<h1>My first web page</h1>
<p>Nothing can stop me now</p>
<a href="http://google.com">My link to Google</a>
</body>
</html>
[root@benji htdocs]#
[root@benji htdocs]#
sample.html
[root@benji htdocs]# ls -l /root/sample.tar
-rw-r--r-- 1 root root 10240 Nov 22 08:56 /root/sample.tar
[root@benji htdocs]#
rm: remove regular file `sample.html'? y
[root@benji htdocs]#
-rw-r--r-- root/root
194 2008-10-24 10:13:10 sample.html
[root@benji htdocs]#
sample.html
[root@benji htdocs]# ls -l sample.html
-rw-r--r-- 1 root root 194 Oct 24 10:13 sample.html
[root@benji htdocs]# cat sample.html
<html>
<head>
<title>My first page</title>
</head>
<body>
<h1>My first web page</h1>
<p>Nothing can stop me now</p>
<a href="http://google.com">My link to Google</a>
</body>
</html>
[root@benji htdocs]#
Backup a web page file
Oops! – file gets deleted
View backed up file
Restore the file
CIS 90 - Lesson 14
tar command
Single file example
verbose
create
tarfile
to use
file to back up
(requires full path)
sample.html
verbose
view (table of
contents)
tarfile
to use
-rw-r--r-- root/root
10:13:10 sample.html
verbose
extract
sample.html
tarfile
to use
194 2008-10-24
file in archive to restore
(requires full path)
CIS 90 - Lesson 14
tar command
Pay attention to the path stored in the tarfile
Creating the tarfile from another directory using absolute path
[root@benji ~]# tar cvf sample2.tar /opt/lampp/htdocs/sample.html
tar: Removing leading `/' from member names
/opt/lampp/htdocs/sample.html
Note, the leading / gets stripped
[root@benji ~]# tar tvf sample2.tar
-rw-r--r-- root/root
194 2008-10-24 10:13:10 opt/lampp/htdocs/sample.html
[root@benji ~]#
This path is used when restoring files
Creating the tarfile from another directory using relative path path
[root@benji ~]# tar cvf sample2.tar ../opt/lampp/htdocs/sample.html
tar: Removing leading `../' from member names
Note, the leading ../ gets stripped
../opt/lampp/htdocs/sample.html
[root@benji ~]# tar tvf sample2.tar
-rw-r--r-- root/root
194 2008-10-24 10:13:10 opt/lampp/htdocs/sample.html
[root@benji ~]#
This path is used when restoring files
CIS 90 - Lesson 14
tar command
-C option
tar
vf tarfile files(s)
The –C option can be used to set the starting
directory for file to be restored to. Add a – to
the other options as well
CIS 90 - Lesson 14
tar command
-C option
Find file to restore in archive
[root@benji ~]#
./xampp/lang/jp.php
Change to the directory where the backup was made
[root@benji lang]# cd /opt/lampp/htdocs/
[root@benji htdocs]#
./xampp/lang/jp.php
[root@benji htdocs]#
Or use the –C option to restore from another directory
[root@benji ~]#
./xampp/lang/jp.php
[root@benji ~]#
CIS 90 - Lesson 14
Class Exercise
tar command
1. Change to the /opt/lampp/htdocs directory.
2. Backup sample.html using:
tar cvf /root/sample.tar sample.html
3. Verify your tarfile contains sample.html
What is the path to sample.html in the tarfile? [Table 1-4]
4. Delete then practice restoring sample.html:
 To its original location
Where did you have to be to do this? [Table 9-12]
 To the /tmp directory
Where did you have to be to do this? [Table 17-20]
5. Now use the tar man page to check out the –C directory option.
 Delete the sample.html in the /tmp directory
 Restore sample.html from /root to the /tmp directory
with the –C option. What command did you use [Table 5-9]?
CIS 90 - Lesson 14
tar command
Directory example
[root@benji htdocs]#
./sample.html
./
./webal izer/
./xampp /
./xampp /lang .tmp
./xampp /xamp p.js
./xampp /inde x.ph p
./xampp /test /
./xampp /test /xam pp_mi ng/
./xampp /test /xam pp_mi ng/gi f.gif
./xampp /test /xam pp_mi ng/jp g.jpg
./xampp /test /xam pp_mi ng/pn g.png
./xampp /test /xam pp_mi ng/bi tmaps .php
./xampp /test /xam pp_wi n.png
./xampp /test /xam pp_mi ng.zi p
./xampp /perl .pl
./xampp /gues tboo k-no. pl
./xampp /spla sh-s wf.ph p
./xampp /gues tboo k-pl. pl
./xampp /ssi. shtm l
./xampp /comp onen ts.ph p
./xampp /cont rib/
./xampp /cont rib/ oracl e.php
./xampp /cont rib/ cds.x ml
./xampp /cont rib/ soap. php
./xampp /cont rib/ sqlit e.php
./xampp /cont rib/ sax.p hp
./xampp /cont rib/ postg resql .pl
./xampp /cont rib/ inter base. pl
./xampp /cont rib/ mysql .php
./xampp /cont rib/ dom.p hp
./xampp /cont rib/ mings tats_ swf.p hp
./xampp /cont rib/ mysql .pl
./xampp /cont rib/ testp erldb i.pl
./xampp /cont rib/ xmlrs s.php
./xampp /cont rib/ mings tats. html
./xampp /cont rib/ sql2x ml.ph p
./xampp /cont rib/ sqlit e.pl
./xampp /cont rib/ Babel Sans- B.fdb
./xampp /cont rib/ oracl e.pl
./xampp /cont rib/ inter base. php
./xampp /cont rib/ postg resql .php
./xampp /manu als. php
./xampp /cgi. cgi
./xampp /cds. php
./xampp /weba lize r.php
./xampp /bior hyth m.php
./xampp /Anke Call igrap h.TTF
./xampp /head .php
./xampp /gues tboo k-zh. pl
./xampp /star t.ph p
./xampp /Anke Call igrap h.fdb
./xampp /ming swf. php
./xampp /mysq l.ph p
./xampp /gues tboo k-nl. pl
./xampp /navi .php
./xampp /lang .php
./xampp /secu rity .php
./xampp /lang /
./xampp /lang /de. php
./xampp /lang /it. php
./xampp /lang /fr. php
./xampp /lang /es. php
./xampp /lang /pt_ br.ph p
./xampp /lang /nl. php
./xampp /lang /zh. php
./xampp /lang /no. php
./xampp /lang /pl. php
./xampp /lang /en. php
./xampp /lang /lan guage s.php
./xampp /lang /jp. php
./xampp /spla sh-l ogo.p hp
./xampp /lang sett ings. php
./xampp /.ver sion
./xampp /stat us.p hp
./xampp /phon eboo k.php
./xampp /img/
./xampp /img/ rb.g if
./xampp /img/ stat us3.g if
./xampp /img/ logo -smal l.gif
./xampp /img/ logo -smal l.jpg
./xampp /img/ new. png
./xampp /img/ sign ature -kay. gif
./xampp /img/ lt.g if
./xampp /img/ benj i-500 x420. jpg
./xampp /img/ stat us4.g if
./xampp /img/ rt.g if
./xampp /img/ stri chel. gif
./xampp /img/ head -linu x.gif
./xampp /img/ head -xamp p.gif
./xampp /img/ xamp p-log o.jpg
./xampp /img/ head -fuer .gif
./xampp /img/ head -for. gif
./xampp /img/ head -sola ris.g if
./xampp /img/ stat us2.g if
./xampp /img/ stat us1.g if
./xampp /img/ head -wind ows.g if
./xampp /img/ logo -big. gif
./xampp /img/ sign ature -oswa ld.gi f
./xampp /img/ stat us5.g if
./xampp /img/ blan k.gif
./xampp /img/ lb.g if
./xampp /img/ xamp p-log o-new .gif
./xampp /img/ apac hefri ends. gif
./xampp /gues tboo k-es. pl
./xampp /gues tboo k-de. pl
./xampp /phpi nfo. php
./xampp /spla sh.p hp
./xampp /gues tboo k-pt_ br.pl
./xampp /gues tboo k.dat
./xampp /char set. php
./xampp /test .php
./xampp /soft ware list. inc
./xampp /gues tboo k-it. pl
./xampp /cds- fpdf .php
./xampp /ssi. inc
./xampp /php. php
./xampp /sqli te/
./xampp /sqli te/c dcol
./xampp /sqli te/p honeb ook.s qlite
./xampp /sqli te/. htacc ess
./xampp /xamp p.cs s
./xampp /ming .php
./xampp /show code .php
./xampp /gues tboo k-fr. pl
./xampp /gues tboo k-en. pl
Backup up files (including
hidden and sub-directories)
starting from "here"
Note how tar saves full path for each file backed up
./xampp/iart.php
./.hidden
Delete some files
[root@benji htdocs]# rm xampp/iart.php .hidden sample.html
rm: remove regular file `xampp/iart.php'? y
rm: remove regular empty file `.hidden'? y
rm: remove regular file `sample.html'? y
[root@benji htdocs]#
-rw-r--r-- root/root
194 2008-10-24 10:13:10 ./sample.html
Verify they
-rw-r--r-- root/root
3004 2006-11-10 08:57:01 ./xampp/iart.php
backed up
-rw-r--r-- root/root
0 2008-11-22 09:23:17 ./.hidden
[root@benji htdocs]#
./sample.html
./xampp/iart.php
Restore the files that were deleted
./.hidden
./favic on.ic o
./index .html
were
CIS 90 - Lesson 14
create
verbose
tarfile
to use
./
./webalizer/
./sample.html
./xampp/
./xampp/lang.tmp
./xampp/xampp.js
./xampp/index.php
./xampp/test/
./xampp/test/xampp_ming/
./xampp/test/xampp_ming/gif.gif
./xampp/test/xampp_ming/jpg.jpg
./xampp/test/xampp_ming/png.png
./xampp/test/xampp_ming/bitmaps.php
./xampp/test/xampp_win.png
./xampp/test/xampp_ming.zip
./xampp/perl.pl
./xampp/guestbook-no.pl
./xampp/splash-swf.php
./xampp/guestbook-pl.pl
./xampp/ssi.shtml
./xampp/components.php
./xampp/contrib/
./xampp/contrib/oracle.php
./xampp/contrib/cds.xml
./xampp/contrib/soap.php
./xampp/contrib/sqlite.php
./xampp/contrib/sax.php
./xampp/contrib/postgresql.pl
./xampp/contrib/interbase.pl
./xampp/contrib/mysql.php
./xampp/contrib/dom.php
./xampp/contrib/mingstats_swf.php
./xampp/contrib/mysql.pl
./xampp/contrib/testperldbi.pl
files to back up
(starting point)
./xampp/contrib/xmlrss.php
./xampp/contrib/mingstats.html
./xampp/contrib/sql2xml.php
./xampp/contrib/sqlite.pl
./xampp/contrib/BabelSans-B.fdb
./xampp/contrib/oracle.pl
./xampp/contrib/interbase.php
./xampp/contrib/postgresql.php
./xampp/manuals.php
./xampp/cgi.cgi
./xampp/cds.php
./xampp/webalizer.php
./xampp/biorhythm.php
./xampp/AnkeCalligraph.TTF
./xampp/head.php
./xampp/guestbook-zh.pl
./xampp/start.php
./xampp/AnkeCalligraph.fdb
./xampp/mingswf.php
./xampp/mysql.php
./xampp/guestbook-nl.pl
./xampp/navi.php
./xampp/lang.php
./xampp/security.php
./xampp/lang/
./xampp/lang/de.php
./xampp/lang/it.php
./xampp/lang/fr.php
./xampp/lang/es.php
./xampp/lang/pt_br.php
./xampp/lang/nl.php
./xampp/lang/zh.php
./xampp/lang/no.php
./xampp/lang/pl.php
tar command
Directory example
./xampp/guestbook-es.pl
./xampp/lang/languages.php
./xampp/guestbook-de.pl
./xampp/lang/jp.php
./xampp/phpinfo.php
./xampp/splash-logo.php
./xampp/splash.php
./xampp/langsettings.php
./xampp/guestbook-pt_br.pl
./xampp/.version
./xampp/guestbook.dat
./xampp/status.php
./xampp/charset.php
./xampp/phonebook.php
./xampp/test.php
./xampp/img/
./xampp/softwarelist.inc
./xampp/img/rb.gif
./xampp/guestbook-it.pl
./xampp/img/status3.gif
./xampp/cds-fpdf.php
./xampp/img/logo-small.gif
./xampp/ssi.inc
./xampp/img/logo-small.jpg
./xampp/php.php
./xampp/img/new.png
./xampp/img/signature-kay.gif ./xampp/sqlite/
./xampp/sqlite/cdcol
./xampp/img/lt.gif
./xampp/img/benji-500x420.jpg ./xampp/sqlite/phonebook.sqlite
./xampp/sqlite/.htaccess
./xampp/img/status4.gif
./xampp/xampp.css
./xampp/img/rt.gif
./xampp/ming.php
./xampp/img/strichel.gif
./xampp/showcode.php
./xampp/img/head-linux.gif
./xampp/guestbook-fr.pl
./xampp/img/head-xampp.gif
./xampp/guestbook-en.pl
./xampp/img/xampp-logo.jpg
./xampp/iart.php
./xampp/img/head-fuer.gif
./.hidden
./xampp/img/head-for.gif
./xampp/img/head-solaris.gif ./favicon.ico
./index.html
./xampp/img/status2.gif
./xampp/img/status1.gif
./xampp/img/head-windows.gif
./xampp/img/logo-big.gif
./xampp/img/signature-oswald.gif
./xampp/img/status5.gif
./xampp/img/blank.gif
./xampp/img/lb.gif
./xampp/img/xampp-logo-new.gif
CIS 90 - Lesson 14
tar command
Directory example
view
(table of contents)
[root@benji htdocs]#
-rw-r--r-- root/root
-rw-r--r-- root/root
-rw-r--r-- root/root
extract
[root@benji htdocs]#
./sample.html
./xampp/iart.php
./.hidden
verbose
tarfile
Files to find in archive
194 2008-10-24 10:13:10 ./sample.html
3004 2006-11-10 08:57:01 ./xampp/iart.php
0 2008-11-22 09:23:17 ./.hidden
verbose
tarfile
Files to find to extract
CIS 90 - Lesson 14
Class Exercise
tar command
1. Change to the /opt/lampp/ directory. Note the htdocs and
backup directories.
2. Backup the htdocs directory (including sub-directories) to
htdocs-20081125.tar
the backup directory.
What command did you use? [Table 21-24]
3. Verify your tarfile contains xampp/lang/jp.php
What command did you use? From where? [Table 1-4]
4. Delete and then restore xampp/lang/jp.php from the backup
directory
What command did you use? [Table 9-12]
CIS 90 - Lesson 14
tar command
Size can differ between tarfile and backed up file
Tarfiles
 Tarfile can be smaller than backed up file as it only
saves the date, not unused portion of data blocks
 Tarfile can be larger if backed up file is a sparse file
 Additional empty blocks can be added to tar version
CIS 90 - Lesson 14
tar command
du size can differ between tarfile and backed up file
Tarfiles
 Additional empty blocks can be added to tar version
[root@benji log]#
ls command show same size for original, copy and tar extracts
[root@benji ~]#
-rw------- 1 root
-rw------- 1 root
-rw------- 1 root
-rw------- 1 root
[root@benji ~]#
root
root
root
root
[root@benji ~]#
messages
/var/log/messages
sparse/messages
nosparse/messages
Nov
Nov
Nov
Nov
22
22
22
22
08:20
08:13
08:13
08:13
messages
nosparse/messages
sparse/messages
/var/log/messages
original file
du report shows more disk space used
than original for copy and tar extracts
Note: the –s option is to handle sparse files (discussed later)
original file
CIS 90 - Lesson 14
tar command
Size can differ between tarfile and backed up file
Tarfiles
 Additional empty blocks can be added to tar version
[root@benji ~]# stat messages /var/log/messages sparse/messages nosparse/messages
File: `messages'
Size: 127538
Blocks: 272
IO Block: 4096
regular file
<snipped>
File: `/var/log/messages'
Size: 127538
Blocks: 254
IO Block: 4096
regular file
<snipped>
File: `sparse/messages'
Size: 127538
Blocks: 272
IO Block: 4096
regular file
<snipped>
File: `nosparse/messages'
Size: 127538
Blocks: 272
IO Block: 4096
regular file
<snipped>
[root@benji ~]#
stat command shows copy and files extracted from tarfile have additional
blocks which explains why file size is the same but disk usage is higher.
CIS 90 - Lesson 14
tar command
sparse files
Sparse Files
 Null blocks (containing only zeroes) are not stored on
the disk
 Can be problematic if utilities don't recognize them
[root@benji ~]# cd /var/log
[root@benji log]# ls -l lastlog
-rw-r--r-- 1 root root 234476 Nov 22 05:18 lastlog
[root@benji log]# du -h lastlog
16K
lastlog
Note the reduced size of the
file actually stored on the
disk using du –h command
CIS 90 - Lesson 14
tar command
sparse files
Sparse Files
 tar command without using the sparse option (-S)
for sparse file
[root@benji ~]# cd /var/log
[root@benji log]# tar cvf /root/lastlog.tar lastlog
lastlog
[root@benji log]# cd /root
[root@benji ~]# ls -l lastlog.tar
-rw-r--r-- 1 root root 245760 Nov 22 05:19 lastlog.tar
[root@benji ~]# du -h lastlog.tar
248K
lastlog.tar
The tarfile has expanded all
the null blocks increasing
[root@benji ~]# tar xvf lastlog.tar
disk space usage
lastlog
[root@benji ~]# ls -l lastlog
-rw-r--r-- 1 root root 234476 Nov 22 05:18 lastlog
[root@benji ~]# du -h lastlog
240K
lastlog
CIS 90 - Lesson 14
tar command
sparse files
Sparse Files
 tar command using the sparse option (-S) with
sparse file
[root@benji ~]# cd /var/log
[root@benji log]# tar cSvf /root/lastlog2.tar lastlog
lastlog
[root@benji log]# cd /root
Using the -S option, the
tar command handles the
[root@benji ~]# tar xvf lastlog2.tar
sparse file efficiently
lastlog
[root@benji ~]# ls -l lastlog
-rw-r--r-- 1 root root 234476 Nov 22 05:18 lastlog
[root@benji ~]# du -h lastlog
20K
lastlog
[root@benji ~]#
CIS 90 - Lesson 14
tar command
compression
c
tar t vf tarfile
x
file(s)
-C dir
The z option uses gzip compresssion and the
j option uses bzip2 compression
bzip2 is slower, but compresses more
gzip is faster, but compreses less
CIS 90 - Lesson 14
tar command
compression
[root@benji htdocs]#
./xampp /lang .tmp
./xampp /xamp p.js
./xampp /inde x.ph p
./xampp /test /
./xampp /test /xam pp_mi ng/
./xampp /test /xam pp_mi ng/gi f.gif
./xampp /test /xam pp_mi ng/jp g.jpg
./xampp /test /xam pp_mi ng/pn g.png
./xampp /test /xam pp_mi ng/bi tmaps .php
./xampp /test /xam pp_wi n.png
./xampp /test /xam pp_mi ng.zi p
./xampp /perl .pl
./xampp /gues tboo k-no. pl
./xampp /spla sh-s wf.ph p
./xampp /gues tboo k-pl. pl
./xampp /ssi. shtm l
./xampp /comp onen ts.ph p
./xampp /cont rib/
./xampp /cont rib/ oracl e.php
./xampp /cont rib/ cds.x ml
./xampp /cont rib/ soap. php
./xampp /cont rib/ sqlit e.php
./xampp /cont rib/ sax.p hp
./xampp /cont rib/ postg resql .pl
./xampp /cont rib/ inter base. pl
./xampp /cont rib/ mysql .php
./xampp /cont rib/ dom.p hp
./xampp /cont rib/ mings tats_ swf.p hp
./xampp /cont rib/ mysql .pl
./xampp /cont rib/ testp erldb i.pl
./xampp /cont rib/ xmlrs s.php
./xampp /cont rib/ mings tats. html
./xampp /cont rib/ sql2x ml.ph p
./xampp /cont rib/ sqlit e.pl
./xampp /cont rib/ Babel Sans- B.fdb
./xampp /cont rib/ oracl e.pl
./xampp /cont rib/ inter base. php
./xampp /cont rib/ postg resql .php
./xampp /manu als. php
./xampp /cgi. cgi
./xampp /cds. php
./xampp /weba lize r.php
./xampp /bior hyth m.php
./xampp /Anke Call igrap h.TTF
./xampp /head .php
./xampp /gues tboo k-zh. pl
./xampp /star t.ph p
./xampp /Anke Call igrap h.fdb
./xampp /ming swf. php
./xampp /mysq l.ph p
./xampp /gues tboo k-nl. pl
./xampp /navi .php
./xampp /lang .php
./xampp /secu rity .php
./xampp /lang /
./xampp /lang /de. php
./xampp /lang /it. php
./xampp /lang /fr. php
./xampp /lang /es. php
./xampp /lang /pt_ br.ph p
./xampp /lang /nl. php
./xampp /lang /zh. php
./xampp /lang /no. php
./xampp /lang /pl. php
./xampp /lang /en. php
./xampp /lang /lan guage s.php
./xampp /lang /jp. php
./xampp /spla sh-l ogo.p hp
./xampp /lang sett ings. php
./xampp /.ver sion
./xampp /stat us.p hp
./xampp /phon eboo k.php
./xampp /img/
./xampp /img/ rb.g if
./xampp /img/ stat us3.g if
./xampp /img/ logo -smal l.gif
./xampp /img/ logo -smal l.jpg
./xampp /img/ new. png
./xampp /img/ sign ature -kay. gif
./xampp /img/ lt.g if
./xampp /img/ benj i-500 x420. jpg
./xampp /img/ stat us4.g if
./xampp /img/ rt.g if
./xampp /img/ stri chel. gif
./xampp /img/ head -linu x.gif
./xampp /img/ head -xamp p.gif
./xampp /img/ xamp p-log o.jpg
./xampp /img/ head -fuer .gif
./xampp /img/ head -for. gif
./xampp /img/ head -sola ris.g if
./xampp /img/ stat us2.g if
./xampp /img/ stat us1.g if
./xampp /img/ head -wind ows.g if
./xampp /img/ logo -big. gif
./xampp /img/ sign ature -oswa ld.gi f
./xampp /img/ stat us5.g if
./xampp /img/ blan k.gif
./xampp /img/ lb.g if
./xampp /img/ xamp p-log o-new .gif
./xampp /img/ apac hefri ends. gif
./xampp /gues tboo k-es. pl
./xampp /gues tboo k-de. pl
./xampp /phpi nfo. php
./xampp /spla sh.p hp
./xampp /gues tboo k-pt_ br.pl
./xampp /gues tboo k.dat
./xampp /char set. php
./xampp /test .php
./xampp /soft ware list. inc
./xampp /gues tboo k-it. pl
./xampp /cds- fpdf .php
./xampp /ssi. inc
./xampp /php. php
./xampp /sqli te/
./xampp /sqli te/c dcol
./xampp /sqli te/p honeb ook.s qlite
./xampp /sqli te/. htacc ess
./xampp /xamp p.cs s
./xampp /ming .php
./xampp /show code .php
./xampp /gues tboo k-fr. pl
./xampp /gues tboo k-en. pl
./xampp /iart .php
./.hidd en
./favic on.ic o
./index .html
Backing up htdocs with no compression
[root@benji htdocs]#
[root@benji backup]#
-rw-r--r-- 1 root root
htdocs.tar
[root@benji backup]#
Nov 22 13:13 htdocs.tar
CIS 90 - Lesson 14
tar command
compression
[root@benji htdocs]#
./
./webal izer/
./sampl e.htm l
./xampp /
./xampp /lang .tmp
./xampp /xamp p.js
./xampp /inde x.ph p
./xampp /test /
./xampp /test /xam pp_mi ng/
./xampp /test /xam pp_mi ng/gi f.gif
./xampp /test /xam pp_mi ng/jp g.jpg
./xampp /test /xam pp_mi ng/pn g.png
./xampp /test /xam pp_mi ng/bi tmaps .php
./xampp /test /xam pp_wi n.png
./xampp /test /xam pp_mi ng.zi p
./xampp /perl .pl
./xampp /gues tboo k-no. pl
./xampp /spla sh-s wf.ph p
./xampp /gues tboo k-pl. pl
./xampp /ssi. shtm l
./xampp /comp onen ts.ph p
./xampp /cont rib/
./xampp /cont rib/ oracl e.php
./xampp /cont rib/ cds.x ml
./xampp /cont rib/ soap. php
./xampp /cont rib/ sqlit e.php
./xampp /cont rib/ sax.p hp
./xampp /cont rib/ postg resql .pl
./xampp /cont rib/ inter base. pl
./xampp /cont rib/ mysql .php
./xampp /cont rib/ dom.p hp
./xampp /cont rib/ mings tats_ swf.p hp
./xampp /cont rib/ mysql .pl
./xampp /cont rib/ testp erldb i.pl
./xampp /cont rib/ xmlrs s.php
./xampp /cont rib/ mings tats. html
./xampp /cont rib/ sql2x ml.ph p
./xampp /cont rib/ sqlit e.pl
./xampp /cont rib/ Babel Sans- B.fdb
./xampp /cont rib/ oracl e.pl
./xampp /cont rib/ inter base. php
./xampp /cont rib/ postg resql .php
./xampp /manu als. php
./xampp /cgi. cgi
./xampp /cds. php
./xampp /weba lize r.php
./xampp /bior hyth m.php
./xampp /Anke Call igrap h.TTF
./xampp /head .php
./xampp /gues tboo k-zh. pl
./xampp /star t.ph p
./xampp /Anke Call igrap h.fdb
./xampp /ming swf. php
./xampp /mysq l.ph p
./xampp /gues tboo k-nl. pl
./xampp /navi .php
./xampp /lang .php
./xampp /secu rity .php
./xampp /lang /
./xampp /lang /de. php
./xampp /lang /it. php
./xampp /lang /fr. php
./xampp /lang /es. php
./xampp /lang /pt_ br.ph p
./xampp /lang /nl. php
./xampp /lang /zh. php
./xampp /lang /no. php
./xampp /lang /pl. php
./xampp /lang /en. php
./xampp /lang /lan guage s.php
./xampp /lang /jp. php
./xampp /spla sh-l ogo.p hp
./xampp /lang sett ings. php
./xampp /.ver sion
./xampp /stat us.p hp
./xampp /phon eboo k.php
./xampp /img/
./xampp /img/ rb.g if
./xampp /img/ stat us3.g if
./xampp /img/ logo -smal l.gif
./xampp /img/ logo -smal l.jpg
./xampp /img/ new. png
./xampp /img/ sign ature -kay. gif
./xampp /img/ lt.g if
./xampp /img/ benj i-500 x420. jpg
./xampp /img/ stat us4.g if
./xampp /img/ rt.g if
./xampp /img/ stri chel. gif
./xampp /img/ head -linu x.gif
./xampp /img/ head -xamp p.gif
./xampp /img/ xamp p-log o.jpg
./xampp /img/ head -fuer .gif
./xampp /img/ head -for. gif
./xampp /img/ head -sola ris.g if
./xampp /img/ stat us2.g if
./xampp /img/ stat us1.g if
./xampp /img/ head -wind ows.g if
./xampp /img/ logo -big. gif
./xampp /img/ sign ature -oswa ld.gi f
./xampp /img/ stat us5.g if
./xampp /img/ blan k.gif
./xampp /img/ lb.g if
./xampp /img/ xamp p-log o-new .gif
./xampp /img/ apac hefri ends. gif
./xampp /gues tboo k-es. pl
./xampp /gues tboo k-de. pl
./xampp /phpi nfo. php
./xampp /spla sh.p hp
./xampp /gues tboo k-pt_ br.pl
./xampp /gues tboo k.dat
./xampp /char set. php
./xampp /test .php
./xampp /soft ware list. inc
./xampp /gues tboo k-it. pl
./xampp /cds- fpdf .php
./xampp /ssi. inc
./xampp /php. php
./xampp /sqli te/
./xampp /sqli te/c dcol
./xampp /sqli te/p honeb ook.s qlite
./xampp /sqli te/. htacc ess
./xampp /xamp p.cs s
./xampp /ming .php
./xampp /show code .php
./xampp /gues tboo k-fr. pl
./xampp /gues tboo k-en. pl
./xampp /iart .php
./.hidd en
./favic on.ic o
./index .html
[root@benji htdocs]#
Post-compression using gzip of archive
[root@benji backup]#
-rw-r--r-- 1 root root
htdocs2.tar.gz
[root@benji backup]#
Nov 22 13:15 htdocs2.tar.gz
CIS 90 - Lesson 14
tar command
compression
[root@benji htdocs]#
./
./webal izer/
./sampl e.htm l
./xampp /
./xampp /lang .tmp
./xampp /xamp p.js
./xampp /inde x.ph p
./xampp /test /
./xampp /test /xam pp_mi ng/
./xampp /test /xam pp_mi ng/gi f.gif
./xampp /test /xam pp_mi ng/jp g.jpg
./xampp /test /xam pp_mi ng/pn g.png
./xampp /test /xam pp_mi ng/bi tmaps .php
./xampp /test /xam pp_wi n.png
./xampp /test /xam pp_mi ng.zi p
./xampp /perl .pl
./xampp /gues tboo k-no. pl
./xampp /spla sh-s wf.ph p
./xampp /gues tboo k-pl. pl
./xampp /ssi. shtm l
./xampp /comp onen ts.ph p
./xampp /cont rib/
./xampp /cont rib/ oracl e.php
./xampp /cont rib/ cds.x ml
./xampp /cont rib/ soap. php
./xampp /cont rib/ sqlit e.php
./xampp /cont rib/ sax.p hp
./xampp /cont rib/ postg resql .pl
./xampp /cont rib/ inter base. pl
./xampp /cont rib/ mysql .php
./xampp /cont rib/ dom.p hp
./xampp /cont rib/ mings tats_ swf.p hp
./xampp /cont rib/ mysql .pl
./xampp /cont rib/ testp erldb i.pl
./xampp /cont rib/ xmlrs s.php
./xampp /cont rib/ mings tats. html
./xampp /cont rib/ sql2x ml.ph p
./xampp /cont rib/ sqlit e.pl
./xampp /cont rib/ Babel Sans- B.fdb
./xampp /cont rib/ oracl e.pl
./xampp /cont rib/ inter base. php
./xampp /cont rib/ postg resql .php
./xampp /manu als. php
./xampp /cgi. cgi
./xampp /cds. php
./xampp /weba lize r.php
./xampp /bior hyth m.php
./xampp /Anke Call igrap h.TTF
./xampp /head .php
./xampp /gues tboo k-zh. pl
./xampp /star t.ph p
./xampp /Anke Call igrap h.fdb
./xampp /ming swf. php
./xampp /mysq l.ph p
./xampp /gues tboo k-nl. pl
./xampp /navi .php
./xampp /lang .php
./xampp /secu rity .php
./xampp /lang /
./xampp /lang /de. php
./xampp /lang /it. php
./xampp /lang /fr. php
./xampp /lang /es. php
./xampp /lang /pt_ br.ph p
./xampp /lang /nl. php
./xampp /lang /zh. php
./xampp /lang /no. php
./xampp /lang /pl. php
./xampp /lang /en. php
./xampp /lang /lan guage s.php
./xampp /lang /jp. php
./xampp /spla sh-l ogo.p hp
./xampp /lang sett ings. php
./xampp /.ver sion
./xampp /stat us.p hp
./xampp /phon eboo k.php
./xampp /img/
./xampp /img/ rb.g if
./xampp /img/ stat us3.g if
./xampp /img/ logo -smal l.gif
./xampp /img/ logo -smal l.jpg
./xampp /img/ new. png
./xampp /img/ sign ature -kay. gif
./xampp /img/ lt.g if
./xampp /img/ benj i-500 x420. jpg
./xampp /img/ stat us4.g if
./xampp /img/ rt.g if
./xampp /img/ stri chel. gif
./xampp /img/ head -linu x.gif
./xampp /img/ head -xamp p.gif
./xampp /img/ xamp p-log o.jpg
./xampp /img/ head -fuer .gif
./xampp /img/ head -for. gif
./xampp /img/ head -sola ris.g if
./xampp /img/ stat us2.g if
./xampp /img/ stat us1.g if
./xampp /img/ head -wind ows.g if
./xampp /img/ logo -big. gif
./xampp /img/ sign ature -oswa ld.gi f
./xampp /img/ stat us5.g if
./xampp /img/ blan k.gif
./xampp /img/ lb.g if
./xampp /img/ xamp p-log o-new .gif
./xampp /img/ apac hefri ends. gif
./xampp /gues tboo k-es. pl
./xampp /gues tboo k-de. pl
./xampp /phpi nfo. php
./xampp /spla sh.p hp
./xampp /gues tboo k-pt_ br.pl
./xampp /gues tboo k.dat
./xampp /char set. php
./xampp /test .php
./xampp /soft ware list. inc
./xampp /gues tboo k-it. pl
./xampp /cds- fpdf .php
./xampp /ssi. inc
./xampp /php. php
./xampp /sqli te/
./xampp /sqli te/c dcol
./xampp /sqli te/p honeb ook.s qlite
./xampp /sqli te/. htacc ess
./xampp /xamp p.cs s
./xampp /ming .php
./xampp /show code .php
./xampp /gues tboo k-fr. pl
./xampp /gues tboo k-en. pl
./xampp /iart .php
./.hidd en
./favic on.ic o
./index .html
[root@benji htdocs]#
Post-compression using bzip2 of archive
[root@benji backup]#
-rw-r--r-- 1 root root
htdocs2.tar.bz2
[root@benji backup]#
Nov 22 13:18 htdocs2.tar.bz2
CIS 90 - Lesson 14
tar command
compression
[root@benji htdocs]#
./
./webal izer/
./sampl e.htm l
./xampp /
./xampp /lang .tmp
./xampp /xamp p.js
./xampp /inde x.ph p
./xampp /test /
./xampp /test /xam pp_mi ng/
./xampp /test /xam pp_mi ng/gi f.gif
./xampp /test /xam pp_mi ng/jp g.jpg
./xampp /test /xam pp_mi ng/pn g.png
./xampp /test /xam pp_mi ng/bi tmaps .php
./xampp /test /xam pp_wi n.png
./xampp /test /xam pp_mi ng.zi p
./xampp /perl .pl
./xampp /gues tboo k-no. pl
./xampp /spla sh-s wf.ph p
./xampp /gues tboo k-pl. pl
./xampp /ssi. shtm l
./xampp /comp onen ts.ph p
./xampp /cont rib/
./xampp /cont rib/ oracl e.php
./xampp /cont rib/ cds.x ml
./xampp /cont rib/ soap. php
./xampp /cont rib/ sqlit e.php
./xampp /cont rib/ sax.p hp
./xampp /cont rib/ postg resql .pl
./xampp /cont rib/ inter base. pl
./xampp /cont rib/ mysql .php
./xampp /cont rib/ dom.p hp
./xampp /cont rib/ mings tats_ swf.p hp
./xampp /cont rib/ mysql .pl
./xampp /cont rib/ testp erldb i.pl
./xampp /cont rib/ xmlrs s.php
./xampp /cont rib/ mings tats. html
./xampp /cont rib/ sql2x ml.ph p
./xampp /cont rib/ sqlit e.pl
./xampp /cont rib/ Babel Sans- B.fdb
./xampp /cont rib/ oracl e.pl
./xampp /cont rib/ inter base. php
./xampp /cont rib/ postg resql .php
./xampp /manu als. php
./xampp /cgi. cgi
./xampp /cds. php
./xampp /weba lize r.php
./xampp /bior hyth m.php
./xampp /Anke Call igrap h.TTF
./xampp /head .php
./xampp /gues tboo k-zh. pl
./xampp /star t.ph p
./xampp /Anke Call igrap h.fdb
./xampp /ming swf. php
./xampp /mysq l.ph p
./xampp /gues tboo k-nl. pl
./xampp /navi .php
./xampp /lang .php
./xampp /secu rity .php
./xampp /lang /
./xampp /lang /de. php
./xampp /lang /it. php
./xampp /lang /fr. php
./xampp /lang /es. php
./xampp /lang /pt_ br.ph p
./xampp /lang /nl. php
./xampp /lang /zh. php
./xampp /lang /no. php
./xampp /lang /pl. php
./xampp /lang /en. php
./xampp /lang /lan guage s.php
./xampp /lang /jp. php
./xampp /spla sh-l ogo.p hp
./xampp /lang sett ings. php
./xampp /.ver sion
./xampp /stat us.p hp
./xampp /phon eboo k.php
./xampp /img/
./xampp /img/ rb.g if
./xampp /img/ stat us3.g if
./xampp /img/ logo -smal l.gif
./xampp /img/ logo -smal l.jpg
./xampp /img/ new. png
./xampp /img/ sign ature -kay. gif
./xampp /img/ lt.g if
./xampp /img/ benj i-500 x420. jpg
./xampp /img/ stat us4.g if
./xampp /img/ rt.g if
./xampp /img/ stri chel. gif
./xampp /img/ head -linu x.gif
./xampp /img/ head -xamp p.gif
./xampp /img/ xamp p-log o.jpg
./xampp /img/ head -fuer .gif
./xampp /img/ head -for. gif
./xampp /img/ head -sola ris.g if
./xampp /img/ stat us2.g if
./xampp /img/ stat us1.g if
./xampp /img/ head -wind ows.g if
./xampp /img/ logo -big. gif
./xampp /img/ sign ature -oswa ld.gi f
./xampp /img/ stat us5.g if
./xampp /img/ blan k.gif
./xampp /img/ lb.g if
./xampp /img/ xamp p-log o-new .gif
./xampp /img/ apac hefri ends. gif
./xampp /gues tboo k-es. pl
./xampp /gues tboo k-de. pl
./xampp /phpi nfo. php
./xampp /spla sh.p hp
./xampp /gues tboo k-pt_ br.pl
./xampp /gues tboo k.dat
./xampp /char set. php
./xampp /test .php
./xampp /soft ware list. inc
./xampp /gues tboo k-it. pl
./xampp /cds- fpdf .php
./xampp /ssi. inc
./xampp /php. php
./xampp /sqli te/
./xampp /sqli te/c dcol
./xampp /sqli te/p honeb ook.s qlite
./xampp /sqli te/. htacc ess
./xampp /xamp p.cs s
./xampp /ming .php
./xampp /show code .php
./xampp /gues tboo k-fr. pl
./xampp /gues tboo k-en. pl
./xampp /iart .php
./.hidd en
./favic on.ic o
./index .html
Using gzip compression option
[root@benji htdocs]#
[root@benji backup]#
-rw-r--r-- 1 root root
htdocs.tar.gz
[root@benji backup]#
Nov 22 13:13 htdocs.tar.gz
CIS 90 - Lesson 14
tar command
compression
[root@benji htdocs]#
./
./webal izer/
./sampl e.htm l
./xampp /
./xampp /lang .tmp
./xampp /xamp p.js
./xampp /inde x.ph p
./xampp /test /
./xampp /test /xam pp_mi ng/
./xampp /test /xam pp_mi ng/gi f.gif
./xampp /test /xam pp_mi ng/jp g.jpg
./xampp /test /xam pp_mi ng/pn g.png
./xampp /test /xam pp_mi ng/bi tmaps .php
./xampp /test /xam pp_wi n.png
./xampp /test /xam pp_mi ng.zi p
./xampp /perl .pl
./xampp /gues tboo k-no. pl
./xampp /spla sh-s wf.ph p
./xampp /gues tboo k-pl. pl
./xampp /ssi. shtm l
./xampp /comp onen ts.ph p
./xampp /cont rib/
./xampp /cont rib/ oracl e.php
./xampp /cont rib/ cds.x ml
./xampp /cont rib/ soap. php
./xampp /cont rib/ sqlit e.php
./xampp /cont rib/ sax.p hp
./xampp /cont rib/ postg resql .pl
./xampp /cont rib/ inter base. pl
./xampp /cont rib/ mysql .php
./xampp /cont rib/ dom.p hp
./xampp /cont rib/ mings tats_ swf.p hp
./xampp /cont rib/ mysql .pl
./xampp /cont rib/ testp erldb i.pl
./xampp /cont rib/ xmlrs s.php
./xampp /cont rib/ mings tats. html
./xampp /cont rib/ sql2x ml.ph p
./xampp /cont rib/ sqlit e.pl
./xampp /cont rib/ Babel Sans- B.fdb
./xampp /cont rib/ oracl e.pl
./xampp /cont rib/ inter base. php
./xampp /cont rib/ postg resql .php
./xampp /manu als. php
./xampp /cgi. cgi
./xampp /cds. php
./xampp /weba lize r.php
./xampp /bior hyth m.php
./xampp /Anke Call igrap h.TTF
./xampp /head .php
./xampp /gues tboo k-zh. pl
./xampp /star t.ph p
./xampp /Anke Call igrap h.fdb
./xampp /ming swf. php
./xampp /mysq l.ph p
./xampp /gues tboo k-nl. pl
./xampp /navi .php
./xampp /lang .php
./xampp /secu rity .php
./xampp /lang /
./xampp /lang /de. php
./xampp /lang /it. php
./xampp /lang /fr. php
./xampp /lang /es. php
./xampp /lang /pt_ br.ph p
./xampp /lang /nl. php
./xampp /lang /zh. php
./xampp /lang /no. php
./xampp /lang /pl. php
./xampp /lang /en. php
./xampp /lang /lan guage s.php
./xampp /lang /jp. php
./xampp /spla sh-l ogo.p hp
./xampp /lang sett ings. php
./xampp /.ver sion
./xampp /stat us.p hp
./xampp /phon eboo k.php
./xampp /img/
./xampp /img/ rb.g if
./xampp /img/ stat us3.g if
./xampp /img/ logo -smal l.gif
./xampp /img/ logo -smal l.jpg
./xampp /img/ new. png
./xampp /img/ sign ature -kay. gif
./xampp /img/ lt.g if
./xampp /img/ benj i-500 x420. jpg
./xampp /img/ stat us4.g if
./xampp /img/ rt.g if
./xampp /img/ stri chel. gif
./xampp /img/ head -linu x.gif
./xampp /img/ head -xamp p.gif
./xampp /img/ xamp p-log o.jpg
./xampp /img/ head -fuer .gif
./xampp /img/ head -for. gif
./xampp /img/ head -sola ris.g if
./xampp /img/ stat us2.g if
./xampp /img/ stat us1.g if
./xampp /img/ head -wind ows.g if
./xampp /img/ logo -big. gif
./xampp /img/ sign ature -oswa ld.gi f
./xampp /img/ stat us5.g if
./xampp /img/ blan k.gif
./xampp /img/ lb.g if
./xampp /img/ xamp p-log o-new .gif
./xampp /img/ apac hefri ends. gif
./xampp /gues tboo k-es. pl
./xampp /gues tboo k-de. pl
./xampp /phpi nfo. php
./xampp /spla sh.p hp
./xampp /gues tboo k-pt_ br.pl
./xampp /gues tboo k.dat
./xampp /char set. php
./xampp /test .php
./xampp /soft ware list. inc
./xampp /gues tboo k-it. pl
./xampp /cds- fpdf .php
./xampp /ssi. inc
./xampp /php. php
./xampp /sqli te/
./xampp /sqli te/c dcol
./xampp /sqli te/p honeb ook.s qlite
./xampp /sqli te/. htacc ess
./xampp /xamp p.cs s
./xampp /ming .php
./xampp /show code .php
./xampp /gues tboo k-fr. pl
./xampp /gues tboo k-en. pl
./xampp /iart .php
./.hidd en
./favic on.ic o
./index .html
Using the bzip2 compression option
[root@benji htdocs]#
[root@benji backup]#
-rw-r--r-- 1 root root
htdocs.tar.bz2
[root@benji backup]#
Nov 22 13:14 htdocs.tar.bz2
CIS 90 - Lesson 14
tar command
compression
[root@benji backup]# ls -Slr
total 2049
-rw-r--r-- 1 root root 340646
-rw-r--r-- 1 root root 340646
-rw-r--r-- 1 root root 343748
-rw-r--r-- 1 root root 343760
-rw-r--r-- 1 root root 706560
[root@benji backup]#
Nov
Nov
Nov
Nov
Nov
22
22
22
22
22
13:14
13:18
13:13
13:15
13:13
htdocs.tar.bz2
htdocs2.tar.bz2
htdocs.tar.gz
htdocs2.tar.gz
htdocs.tar
Conclusions:
• compression option slightly better than two steps
• bzip2 compresses more that gzip
2 steps
CIS 90 - Lesson 14
tar command
compression
[root@benji htdocs]# rm sample.html
rm: remove regular file `sample.html'? y
[root@benji htdocs]#
./sample.html
[root@benji htdocs]# cat sample.html
<html>
<head>
<title>My first page</title>
</head>
<body>
<h1>My first web page</h1>
<p>Nothing can stop me now</p>
<a href="http://google.com">My link to Google</a>
</body>
</html>
FYI, not specifying the z option still works when restoring a file
CIS 90 - Lesson 14
tar command
compression
[root@benji htdocs]# rm sample.html
rm: remove regular file `sample.html'? y
[root@benji htdocs]#
./sample.html
[root@benji htdocs]# cat sample.html
<html>
<head>
<title>My first page</title>
</head>
<body>
<h1>My first web page</h1>
<p>Nothing can stop me now</p>
<a href="http://google.com">My link to Google</a>
</body>
</html>
[root@benji htdocs]#
FYI, not specifying the j option still works when restoring a file
CIS 90 - Lesson 14
Class Exercise
tar command
1. Change to the /opt/lampp/htdocs directory.
2. Make four backups of htdocs into the /root directory using both
compression options and using post compression with gzip and
bzip2.
a) -z option
b) -j option
c) 2 steps with gzip command
d) 2 steps with bzip2 command
3. Verify your backup by deleting, restoring and viewing
sample.html for each backup above
What
What
What
What
commands
commands
commands
commands
did
did
did
did
you
you
you
you
use
use
use
use
for
for
for
for
2a and 3? [Table 17-20]
2b and 3? [Table 5-8]
2c and 3? [Table 13-16]
2d and 3? [Table 21-24]
CIS 90 - Lesson 14
tar command
compression
c
z
tarfile
tar t vf
j
x
file(s)
Backups can be made to devices as well
CIS 90 - Lesson 14
tar command
using devices
[root@benji bin]# fdisk /dev/sda
Command (m for help): n
First cylinder (582-652, default 582):
Using default value 582
Last cylinder or +size or +sizeM or +sizeK (582-652, default 652): +500M
Command (m for help): p
Disk /dev/sda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Make a 500 MB partition
Device Boot
/dev/sda1
*
/dev/sda2
/dev/sda3
/dev/sda4
/dev/sda5
/dev/sda6
/dev/sda7
/dev/sda8
Id
83
82
83
5
83
83
83
83
Start
1
383
448
512
512
550
557
582
Command (m for help):
End
382
447
511
652
549
556
581
643
Blocks
3068383+
522112+
514080
1132582+
305203+
56196
200781
497983+
System
Linux
Linux swap / Solaris
Linux
Extended
Linux
Linux
Linux
Linux
CIS 90 - Lesson 14
tar command
using devices
Command (m for help): x
Expert command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@benji bin]# partprobe
[root@benji bin]#
Use partprobe so kernel will use new partition table
CIS 90 - Lesson 14
tar command
using devices
Change to the directory to back up. Note /dev/sda8 is not mounted
[root@benji opt]#
[root@benji opt]# wc -l /root/errors /root/optfiles
3 /root/errors
/root/optfiles
13285 total
[root@benji opt]#
[root@benji opt]# cat /root/errors
tar: ./lampp/logs/cgisock.2381: socket ignored
tar: ./lampp/logs/cgisock.2404: socket ignored
tar: ./lampp/var/mysql/mysql.sock: socket ignored
You don't need to backup socket files.
They are created automatically by the
kernel when needed
CIS 90 - Lesson 14
tar command
using devices
[root@benji opt]# cd lampp/htdocs
[root@benji htdocs]# rm sample.html
rm: remove regular file `sample.html'?
[root@benji htdocs]#
[root@benji opt]#
-rw-r--r-- root/root
Oops! …. file gets deleted
Finding file in archive
194 2008-10-24 10:13:10 ./lampp/htdocs/sample.html
Restoring deleted file
from backup archive
on a device
[root@benji opt]#
./lampp/htdocs/sample.html
[root@benji opt]# cat lampp/htdocs/sample.html
<html>
<head>
<title>My first page</title>
</head>
Viewing
<body>
<h1>My first web page</h1>
<p>Nothing can stop me now</p>
<a href="http://google.com">My link to Google</a>
</body>
</html>
[root@benji opt]#
restored file
CIS 90 - Lesson 14
tar command
Examples
Perform full backup of entire file tree
#
#
#
Don't backup and restore /proc (this is real time kernel data) !!
#
-p, --same-permissions, --preserve-permissions
Keeps permissions of extracted files the same as the originals.
CIS 90 - Lesson 14
tar command
Examples
Backup files in /opt after May 5, 1993
#
#
This allows differential and incremental backups to be done. Both types
are based on a date. Either the last backup (incremental) or the last full
backup (differential).
To do differential or incremental backups you will need a mechanism to
track the dates or use a higher level backup program that makes use of
tar.
CIS 90 - Lesson 14
Class Exercise
tar command
1. Create a 500 MB partition on /dev/sda
2. Backup the entire /opt directory to this partition using tar
What commands did you use? [Table 1-4]
3. Verify your backup by deleting, restoring and viewing
sample.html for each backup above
What commands did you use? [Table 9-12]
4. Delete the 500 MB partition
CIS 90 - Lesson 14
Class Exercise
tar
On Opus, tar up you entire home directory. Use your own
logname to name the tarball:
cd
tar cvf logname.tar *
On your local vm, create a directory with the same name as your
Opus logname and change into it.
mkdir logname
cd logname/
scp logname@opus.cabrillo.edu:*.tar .
tar xvf logname.tar
CIS 90 - Lesson 14
Wrap up
CIS 90 - Lesson 14
Next Class
Project is due next week!
CIS 90 - Lesson 14
Backup
Download