[SunHELP] Tar & exclusions
Lund, Dennis
sunhelp at sunhelp.org
Wed Nov 7 12:28:01 CST 2001
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C167B9.EEEEC280
Content-Type: text/plain
Take a look at these extracts from a newsletter column titled "Trimming Tar
Files" By Sandra Henry-Stocker
In this newsletter, we're going to look at a simple script for creating
tar files free of unwanted clutter. Using this script, you will still
have to identify the files that you want to omit, but you can do so
once rather than including the file names every time you create a tar
file.
Before we look at the script, let's review the tar command's option for
excluding files. The exclude option is called into play using the X
option. The corresponding argument identifies the file containing the
names of files to be excluded. Since tar's options are positional, the
X option must occupy the same position in the option list as the
argument in the argument list. In other words, either of the following
syntax forms would be acceptable:
tar cvfX <tarfile> <exclude-file> <file list>
or
tar cvXf <exclude-file> <tarfile> <file list>
If the directory that you're tarring up is static, you can easily
create an exclude file and use it all the time. It's when the contents
of the directory change regularly that you'll save yourself work by
creating an exclude file "on the fly".
Simply putting "logs" in the exclude file would only omit the "logs"
directory (or a "logs" file) if it were in the immediate directory.
Therefore, we need to be a bit more clever. In the script below, we use
the find command to create a list of files to be excluded. The find
command allows us to create a list based using regular expressions.
For example, we're going to omit any directories that are called "logs"
or anything ending with the word "logs".
----------------------------- cut here ---------------------------------
#!/bin/sh
#
# tar-wo-logs
PWD=`pwd`
if [ $# = 0 ]; then
echo Enter directory name
read DIR
cd $DIR
else
cd $1
fi
echo "/opt/jrun/jsm-default/services/jse/servlets/jsp" > /tmp/$$
find . -type d -name "*logs" -print | sed "s,^./,," >> /tmp/$$
find . -type d -name "cache" -print| sed "s,^./,," >> /tmp/$$
find . -type d -name "core" -print| sed "s,^./,," >> /tmp/$$
BASE=`basename $DIR`
tar cvXf /tmp/$$ $PWD/$BASE.tar *
rm /tmp/$$
----------------------------- cut here ---------------------------------
The script first checks to see whether it was invoked with arguments.
If it was, it prompts for the name of the directory to be tarred up.
It then creates an exclude file using a series of find commands,
storing it in /tmp.
The script uses the base command to create a simple name for the tar
file. For example, if we are tarring up /usr/gnu, the resultant tar
file will be called gnu.tar. As a last step, we get rid of the temp
file (my Mom always told me to clean up after myself).
Hope this helps.
Dennis L. Lund
-----Original Message-----
From: Steve Wingate [mailto:steve at velosystems.net]
Sent: Wednesday, November 07, 2001 1:07 PM
To: sunhelp at sunhelp.org
Subject: [SunHELP] Tar & exclusions
I'm trying to get tar to exclude backing up the /dev/fd directory but I
can't get it to work. It still gets stuck on scrolling "a /dev/fd/0 0 tape
blocks" forever. This is a Sparc20 w/no floppy at all. Here is the command
I'm running:
# tar cvX excludes /
The excludes file contains the following
/proc
/dev
/etc/mnttab
/var/run
/tmp
/cdrom
/devices
/floppy
I tried a test by running "tar cvX test /var" with the test file only
containing
/var/run
and it worked perfectly. I don't see the difference in the two commands
besides the target. What am I missing here? And yes, I've been reading 'man
tar' for many many hours. I tried putting "/dev/fd" in the excludes file
also to no avail. I HATE man pages w/o decent examples.
This is Sun tar, not gtar.
+---------------------------------------------------------------------+
|Steve Wingate <stevew at velosystems.net> 310.544.9920 |
|MCSE, CCNA, no JOB Wed Nov 7 09:17:01 PST 2001 |
+---------------------------------------------------------------------+
|FreeBSD 4.4-STABLE
| 9:17AM up 8:52, 4 users, load averages: 0.16, 0.05, 0.02
+---------------------------------------------------------------------+
_______________________________________________
SunHELP maillist - SunHELP at sunhelp.org
http://www.sunhelp.org/mailman/listinfo/sunhelp
<html>
<body>
<font size="3" face="Times New Roman"><span style="mso-fareast-font-family: Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">
- - - - - - - Appended by Scientific-Atlanta, Inc. - - - - - - -
<span style="font-size:10.0pt;font-family:Times New Roman;
mso-fareast-font-family:"Times New Roman";mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:AR-SA"></span><font face="Times New Roman" size="3"><span style="mso-fareast-font-family:Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">This e-mail and any attachments may contain information which is confidential, proprietary, privileged or otherwise protected by law. The information is solely intended for the named addressee (or a person responsible for delivering it to the addressee). If you are not the intended recipient of this message, you are not authorized to read, print, retain, copy or disseminate this message or any part of it. If you have received this e-mail in error, please notify the sender immediately by return e-mail and delete it from your computer.</span></font></p>
</body>
</html>
------_=_NextPart_001_01C167B9.EEEEC280
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; charset=3DUS-ASCII">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version 5.5.2654.45">
<TITLE>RE: [SunHELP] Tar & exclusions</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=3D2>Take a look at these extracts from a newsletter column ti=
tled "Trimming Tar Files" By Sandra Henry-Stocker</FONT>
</P>
<P><FONT SIZE=3D2>In this newsletter, we're going to look at a simple scrip=
t for creating </FONT>
<BR><FONT SIZE=3D2>tar files free of unwanted clutter. Using this script, y=
ou will still </FONT>
<BR><FONT SIZE=3D2>have to identify the files that you want to omit, but yo=
u can do so </FONT>
<BR><FONT SIZE=3D2>once rather than including the file names every time you=
create a tar </FONT>
<BR><FONT SIZE=3D2>file.</FONT>
</P>
<P><FONT SIZE=3D2>Before we look at the script, let's review the tar comman=
d's option for </FONT>
<BR><FONT SIZE=3D2>excluding files. The exclude option is called into play =
using the X </FONT>
<BR><FONT SIZE=3D2>option. The corresponding argument identifies the =
file containing the </FONT>
<BR><FONT SIZE=3D2>names of files to be excluded. Since tar's options=
are positional, the </FONT>
<BR><FONT SIZE=3D2>X option must occupy the same position in the option lis=
t as the </FONT>
<BR><FONT SIZE=3D2>argument in the argument list. In other words, eit=
her of the following </FONT>
<BR><FONT SIZE=3D2>syntax forms would be acceptable:</FONT>
</P>
<P><FONT SIZE=3D2> tar cvfX <tarfile> <exclude-f=
ile> <file list></FONT>
</P>
<P><FONT SIZE=3D2>or</FONT>
</P>
<P><FONT SIZE=3D2> tar cvXf <exclude-file> <tarf=
ile> <file list></FONT>
</P>
<P><FONT SIZE=3D2>If the directory that you're tarring up is static, you ca=
n easily </FONT>
<BR><FONT SIZE=3D2>create an exclude file and use it all the time. It=
's when the contents </FONT>
<BR><FONT SIZE=3D2>of the directory change regularly that you'll save yours=
elf work by </FONT>
<BR><FONT SIZE=3D2>creating an exclude file "on the fly".</FONT>
</P>
<P><FONT SIZE=3D2>Simply putting "logs" in the exclude file would=
only omit the "logs" </FONT>
<BR><FONT SIZE=3D2>directory (or a "logs" file) if it were in the=
immediate directory. </FONT>
<BR><FONT SIZE=3D2>Therefore, we need to be a bit more clever. In the scrip=
t below, we use </FONT>
<BR><FONT SIZE=3D2>the find command to create a list of files to be exclude=
d. The find </FONT>
<BR><FONT SIZE=3D2>command allows us to create a list based using regular e=
xpressions. </FONT>
<BR><FONT SIZE=3D2>For example, we're going to omit any directories that ar=
e called "logs" </FONT>
<BR><FONT SIZE=3D2>or anything ending with the word "logs".</FONT>
</P>
<P><FONT SIZE=3D2>----------------------------- cut here ------------------=
---------------</FONT>
<BR><FONT SIZE=3D2>#!/bin/sh</FONT>
<BR><FONT SIZE=3D2>#</FONT>
<BR><FONT SIZE=3D2># tar-wo-logs</FONT>
</P>
<P><FONT SIZE=3D2>PWD=3D`pwd`</FONT>
</P>
<P><FONT SIZE=3D2>if [ $# =3D 0 ]; then</FONT>
<BR><FONT SIZE=3D2> echo Enter directory name</FONT>
<BR><FONT SIZE=3D2> read DIR</FONT>
<BR><FONT SIZE=3D2> cd $DIR</FONT>
<BR><FONT SIZE=3D2>else</FONT>
<BR><FONT SIZE=3D2> cd $1</FONT>
<BR><FONT SIZE=3D2>fi</FONT>
</P>
<P><FONT SIZE=3D2>echo "/opt/jrun/jsm-default/services/jse/servlets/js=
p" > /tmp/$$</FONT>
<BR><FONT SIZE=3D2>find . -type d -name "*logs" -print | sed &quo=
t;s,^./,," >> /tmp/$$</FONT>
<BR><FONT SIZE=3D2>find . -type d -name "cache" -print| sed "=
;s,^./,," >> /tmp/$$</FONT>
<BR><FONT SIZE=3D2>find . -type d -name "core" -print| sed "=
s,^./,," >> /tmp/$$</FONT>
<BR><FONT SIZE=3D2>BASE=3D`basename $DIR`</FONT>
<BR><FONT SIZE=3D2>tar cvXf /tmp/$$ $PWD/$BASE.tar *</FONT>
<BR><FONT SIZE=3D2>rm /tmp/$$</FONT>
<BR><FONT SIZE=3D2>----------------------------- cut here -----------------=
----------------</FONT>
</P>
<P><FONT SIZE=3D2>The script first checks to see whether it was invoked wit=
h arguments. </FONT>
<BR><FONT SIZE=3D2>If it was, it prompts for the name of the directory to b=
e tarred up. </FONT>
<BR><FONT SIZE=3D2>It then creates an exclude file using a series of find c=
ommands, </FONT>
<BR><FONT SIZE=3D2>storing it in /tmp.</FONT>
</P>
<P><FONT SIZE=3D2>The script uses the base command to create a simple name =
for the tar </FONT>
<BR><FONT SIZE=3D2>file. For example, if we are tarring up /usr/gnu, =
the resultant tar </FONT>
<BR><FONT SIZE=3D2>file will be called gnu.tar. As a last step, we ge=
t rid of the temp </FONT>
<BR><FONT SIZE=3D2>file (my Mom always told me to clean up after myself).</=
FONT>
</P>
<P><FONT SIZE=3D2>Hope this helps.</FONT>
</P>
<P><FONT SIZE=3D2>Dennis L. Lund</FONT>
</P>
<P><FONT SIZE=3D2>-----Original Message-----</FONT>
<BR><FONT SIZE=3D2>From: Steve Wingate [<A HREF=3D"mailto:steve at velosystems=
.net">mailto:steve at velosystems.net</A>]</FONT>
<BR><FONT SIZE=3D2>Sent: Wednesday, November 07, 2001 1:07 PM</FONT>
<BR><FONT SIZE=3D2>To: sunhelp at sunhelp.org</FONT>
<BR><FONT SIZE=3D2>Subject: [SunHELP] Tar & exclusions</FONT>
</P>
<BR>
<P><FONT SIZE=3D2>I'm trying to get tar to exclude backing up the /dev/fd d=
irectory but I can't get it to work. It still gets stuck on scrolling "=
;a /dev/fd/0 0 tape blocks" forever. This is a Sparc20 w/no floppy at =
all. Here is the command I'm running:</FONT></P>
<P><FONT SIZE=3D2># tar cvX excludes /</FONT>
</P>
<P><FONT SIZE=3D2>The excludes file contains the following </FONT>
<BR><FONT SIZE=3D2>/proc</FONT>
<BR><FONT SIZE=3D2>/dev</FONT>
<BR><FONT SIZE=3D2>/etc/mnttab</FONT>
<BR><FONT SIZE=3D2>/var/run</FONT>
<BR><FONT SIZE=3D2>/tmp</FONT>
<BR><FONT SIZE=3D2>/cdrom</FONT>
<BR><FONT SIZE=3D2>/devices</FONT>
<BR><FONT SIZE=3D2>/floppy</FONT>
</P>
<P><FONT SIZE=3D2>I tried a test by running "tar cvX test /var" w=
ith the test file only containing</FONT>
<BR><FONT SIZE=3D2>/var/run</FONT>
<BR><FONT SIZE=3D2>and it worked perfectly. I don't see the difference in t=
he two commands besides the target. What am I missing here? And yes, I've b=
een reading 'man tar' for many many hours. I tried putting "/dev/fd&qu=
ot; in the excludes file also to no avail. I HATE man pages w/o decent exam=
ples. </FONT></P>
<P><FONT SIZE=3D2>This is Sun tar, not gtar.</FONT>
</P>
<BR>
<BR>
<P><FONT SIZE=3D2>+--------------------------------------------------------=
-------------+</FONT>
<BR><FONT SIZE=3D2>|Steve Wingate <stevew at velosystems.net>  =
; &n=
bsp; 310.544.9920 |</FONT>
<BR><FONT SIZE=3D2>|MCSE, CCNA, no JOB &=
nbsp; &nbs=
p; Wed Nov 7 09:17:01 PST 2001 |</FONT>
<BR><FONT SIZE=3D2>+-------------------------------------------------------=
--------------+</FONT>
<BR><FONT SIZE=3D2>|FreeBSD 4.4-STABLE &=
nbsp; &nbs=
p; &=
nbsp; &nbs=
p; </FONT>
<BR><FONT SIZE=3D2>| 9:17AM up 8:52, 4 users, load averages: 0.=
16, 0.05, 0.02 </FONT>
<BR><FONT SIZE=3D2>+-------------------------------------------------------=
--------------+</FONT>
<BR><FONT SIZE=3D2>_______________________________________________</FONT>
<BR><FONT SIZE=3D2>SunHELP maillist - SunHELP at sunhelp.org</FONT>
<BR><FONT SIZE=3D2><A HREF=3D"http://www.sunhelp.org/mailman/listinfo/sunhe=
lp" TARGET=3D"_blank">http://www.sunhelp.org/mailman/listinfo/sunhelp</A></=
FONT>
</P>
<CODE><FONT SIZE=3D3><BR>
<BR>
<html><BR>
<body><BR>
<font size=3D"3" face=3D"Times New Roman"><span style=3D"mso-fareast-font-f=
amily: Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: EN-=
US; mso-bidi-language: AR-SA"><BR>
- - - - - - - Appended by Scientific-Atlanta, Inc. - - - - - - -<BR>
<span style=3D"font-size:10.0pt;font-family:Times New Roman;<BR>
mso-fareast-font-family:"Times New Roman";mso-ansi-language:EN-US=
;mso-fareast-language:<BR>
EN-US;mso-bidi-language:AR-SA"></span><font face=3D"Times New Roman" size=
=3D"3"><span style=3D"mso-fareast-font-family:Times New Roman; mso-ansi-lan=
guage: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">This e=
-mail and any attachments may contain information which is confidential, pr=
oprietary, privileged or otherwise protected by law. The information is sol=
ely intended for the named addressee (or a person responsible for deliverin=
g it to the addressee). If you are not the intended recipient of this messa=
ge, you are not authorized to read, print, retain, copy or disseminate this=
message or any part of it. If you have received this e-mail in error, plea=
se notify the sender immediately by return e-mail and delete it from your c=
omputer.</span></font></p><BR>
</body><BR>
</html><BR>
</FONT></CODE></BODY>
</HTML>
------_=_NextPart_001_01C167B9.EEEEC280--
More information about the SunHELP
mailing list