old-www/LDP/LG/issue63/tag/1.html

315 lines
13 KiB
HTML

<!--startcut ======================================================= -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<META NAME="generator" CONTENT="lgazmail v1.3E.n">
<TITLE>The Answer Gang 63: Why is diff so crazy?</TITLE>
</HEAD><BODY BGCOLOR="#FFFFFF" TEXT="#000000"
LINK="#3366FF" VLINK="#A000A0">
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<P> <hr>
<CENTER>
<!-- *** BEGIN navbar *** -->
<!-- *** END navbar *** -->
</CENTER>
</p>
<P> <hr> <P>
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<center>
<H1><A NAME="answer">
<img src="../../gx/dennis/qbubble.gif" alt="(?)"
border="0" align="middle">
<font color="#B03060">The Answer Gang</font>
<img src="../../gx/dennis/bbubble.gif" alt="(!)"
border="0" align="middle">
</A></H1>
<BR>
<H4>By Jim Dennis, Ben Okopnik, Dan Wilder, the Editors of <em>Linux Gazette</em>...
and You!
<br>Send questions (or interesting answers) to
<a href="mailto:linux-questions-only@ssc.com">linux-questions-only@ssc.com</a>
</H4>
</center>
<p><hr><p>
<!-- endcut ======================================================= -->
<!-- begin 23 -->
<H3 align="left"><img src="../../gx/dennis/qbubble.gif"
height="50" width="60" alt="(?) " border="0"
>Why is diff so crazy?</h3>
<h4 align="center">Perseverence pays off at last.</H4>
<p><strong>From sbcs
</strong></p>
<p align="right"><strong>Answered By Heather Stern
<br></strong></p>
<!-- sig -->
<!-- ::
Why is diff so crazy? -- Perseverence pays off at last.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:: -->
<BLOCKQUOTE>
This is the reformatting and basically kick-in-the-pants of a question
that's been in the mill for a few months. For 3 months this fellow
patiently sent the message again, certain that someday, we would get to him.
</BLOCKQUOTE>
<BLOCKQUOTE>
Before I get started with the actual question, I'd like to make it completely
clear to our readers... we do enjoy answering questions. For some strange
reason, that is part of what is fun about Linux for those of us here in the
Answer Gang. The <EM>Gazette</EM> exists to <EM>make Linux a little more
fun</EM> so here we are.
</BLOCKQUOTE>
<BLOCKQUOTE>
However, we're all volunteers, we all have day jobs and most of us have
families and pillows we like to visit with once in a while. There is no
guarantee that anyone who sends us mail gets an answer.
</BLOCKQUOTE>
<BLOCKQUOTE>
[ He also had some problems that made his mail a good candidate to get
ignored. Since we had another thread elsewhere on features that will help
you get an answer, I moved my comments there, and you saw those in
<a href="../../issue62/tag/5.html">Creed of the Querent</a> earlier this month. ]
</BLOCKQUOTE>
<BLOCKQUOTE>
I've added paragraphs, and hit it with my best shot, and maybe the Gang can
help out a bit further. Comments from you, gentle readers, are always
welcome too!
</BLOCKQUOTE>
<BLOCKQUOTE>
So now, on to the tasty question.
</BLOCKQUOTE>
<P><STRONG><IMG SRC="../../gx/dennis/qbub.gif" ALT="(?)"
HEIGHT="28" WIDTH="50" BORDER="0"
>
I wanted to build a fresh installation on my portable (<A HREF="http://www.redhat.com/">Red Hat</A> 5.2
upgraded to 6.0), but I didn't want to just erase the old one.
</STRONG></P>
<P><STRONG>
So I pulled the notebook's hard drive, plugged it into my server (Red
Hat 6.2) and archived the contents with <tt>cp -a</tt> file file. The -a
(archive) tells cp to preserve links, preserve file attributes if
possible and to copy directories recursively. The copy process didn't
return any errors... so far so good.
</STRONG></P>
<BLOCKQUOTE><IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [Heather]
Okay. So far, we have that you wanted to upgrade, so you planned to back
it up. That's a good idea, but the method isn't so hot.
</BLOCKQUOTE>
<BLOCKQUOTE>
<tt>cp -a</tt> really only works if you're root, and I can't tell if you
were, or not. But it's not the method I would use to do a proper backup of
everything. I normally use GNU tar:
</BLOCKQUOTE>
<blockquote><BLOCKQUOTE><code>cd /mnt/otherbox
<br>tar czvfpS /usr/local/otherbox-60-backup.tgz .
</code></BLOCKQUOTE></blockquote>
<BLOCKQUOTE>
The options stand for (in order) [c]reate, use g[z]ip compression, be
[v]erbose, send the output to a [f]ile instead of a tape (this option
needs a parameter), save the [p]ermissions, be careful about [S]parse
files if they exist. The file parameter given has a tgz extension to
remind myself later that it's a tar in gzip format, and I put it in
<TT>/usr/local</TT> because that usually has lots of free space. The
very last parameter is a period, so that I'm indicating the current
directory. I do not want to accidentally mix up any parts from my
server into my otherbox backup.
</BLOCKQUOTE>
<BLOCKQUOTE>
Among other things it properly deals with backing up device files...
all those strange things you'd normally use mknod to create.
</BLOCKQUOTE>
<BLOCKQUOTE><IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [Mike]
Before untarring, you MUST do "umask 000" or risk having
/dev/null and other stuff not be world-writable.
</BLOCKQUOTE>
<BLOCKQUOTE><IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [Heather] I haven't encountered that (I think this is what the
p flag for tar solves) but good catch!
Now this works okay for most circumstances and the nice thing is that you
have a very easy way to check it is okay:
</BLOCKQUOTE>
<BLOCKQUOTE><BLOCKQUOTE><CODE>
tar dzvfpS /usr/local/otherbox-60-backup.tgz .
</CODE></BLOCKQUOTE></BLOCKQUOTE>
<BLOCKQUOTE>
Where the d stands for diff and all the rest is the same. Diff does have
a glitch, and will complain about one special kind of file called a socket.
X often has at least one of these, the log system usually uses one, and the
mouse often uses one too. It's okay to ignore that because a socket depends
on the context of the program that owns it, and right now, there's no program
running from that disk to give it the right context anyway. (Okay. I'm
guessing. but, that is a theory I have which seems to fit all the ways I
see sockets used.)
</BLOCKQUOTE>
<BLOCKQUOTE>
Now my husband Jim doesn't always trust tar, and sometimes uses cpio. I'll
let him or one of the rest of the Gang answer with a better description of
using cpio correctly. What I will tell you is why. When you are about to
do a full restore of a tarball, it checks to see if can assign the permissions
back to the correct original owners. However, a <EM>complete</EM> restore
will be to an empty disk, which won't have correct passwd and group files
yet. Oops.
</BLOCKQUOTE>
<BLOCKQUOTE>
But there is a fix for this too, and I use it all the time when restoring:
</BLOCKQUOTE>
<BLOCKQUOTE><BLOCKQUOTE><code>cd /mnt/emptydisk
<br>tar xzvfpS --numeric-owner /usr/local/otherbox-60-backup.tgz .
</code></BLOCKQUOTE></BLOCKQUOTE>
<BLOCKQUOTE>It's just as valid to use midnight commander to create
/mnt/emptydisk/etc, open up the backup tgz file, and copy across
the precious /etc/shadow, /etc/group, and /etc/passwd files
before issuing your restore command.
</BLOCKQUOTE>
<P><STRONG><IMG SRC="../../gx/dennis/qbub.gif" ALT="(?)"
HEIGHT="28" WIDTH="50" BORDER="0"
>
But when I ran diff -r file file, I got screen-fulls of errors. The
most obvious problem was that diff was stuck in a loop with
"<TT>/usr/bin/mh</TT>", a symbolic link pointing back to "<TT>/usr/bin</TT>".
<IMG SRC="../../gx/dennis/smily.gif" ALT=":-)"
height="24" width="20" align="middle"> Make a
pair of directories, each containing a symbolic link pointing back at
the directory it resides in, and then run diff -r on those two
directories and you can see what I mean.
</STRONG></P>
<P><STRONG>
The diff program doesn't fail on all symbolic links... just those that
lead into loops and some others (I didn't take time to explore what it
was about the others). I removed "<TT>/usr/bin/mh</TT>" (I'd have preferred not
to have had to, but I wanted to move along and see what other snags I
could hit), ran diff again with output redirected to a file and
started taking the file apart with grep and wc to find out what
general classes of error I was dealing with... turns out diff was
failing on "character special" files, sockets and "block special"
files.
</STRONG></P>
<P><STRONG>
I don't know what any of those three are, but I used find and wc again
on the file system and discovered that diff was failing on every
single one that it tried to compare. Does anybody know what to do
about these problems?
</STRONG></P>
<P><STRONG>
update: After a week of trying, I'm unable to duplicate the event
above. I installed Red Hat 6.0 on a pair of Gateways... basically the
same procedure as I did for my disk usage article at the other end of
that link.
</STRONG></P>
<P><STRONG>
When I ran the diff, it seemed to start looping somewhere in
"<TT>/tmp/orbit-root</TT>"... I let it run for about 24 hours and the hard
drive light was still flashing the next day, no error message.
</STRONG></P>
<P><STRONG>
I tried 6.0 transplanted into a 6.2 box... same thing. I put 6.0 on my
portable, pulled the drive and attached it to my server, and got the
same thing. I put 5.2 on my portable, upgraded it to 6.0, pulled the
drive and attached it to my server... same circumstances as the
original event... and diff looped somewhere in "<TT>/tmp/.X11-unix</TT>"
instead of "<TT>/tmp/orbit-root</TT>".
</STRONG></P>
<BLOCKQUOTE><IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [Heather]
I simply don't recommend that full backups ever waste any time
capturing /tmp. The point of this directory is to have a big
place where programs can create the files if they need to. Make
the programs do their own dirty work making sure they have the
right parts. In my case, /tmp is a seperate partition, and I
wouldn't even mount it in rescue mode.
</BLOCKQUOTE>
<BLOCKQUOTE>While we're at mentioning filesystems to skip, make sure not
to bother getting the /proc filesystem, either. The -l (little
ell) switch to tar when making a backup, will make sure it won't
wander across filesystem borders unless you specify them on the
command line.
</BLOCKQUOTE>
<BLOCKQUOTE><BLOCKQUOTE><tt>cd /mnt/otherdisk</tt>
<br>(mount its subvolumes here ... skip tmp, proc, and devfs if you have it)
<br><tt>tar czvfpSl /usr/local/otherbox-60-backup.tgz . usr var home
</tt></BLOCKQUOTE></BLOCKQUOTE>
<P><STRONG><IMG SRC="../../gx/dennis/qbub.gif" ALT="(?)"
HEIGHT="28" WIDTH="50" BORDER="0"
>
The diff program definitely has issues with most types of non-regular
files (directories excluded), as well as the problem of at other times
looping without ever generating an error message (which could, of
course, be related to the same basic problem with non-regular files).
Suggestion(s), anyone?
<IMG SRC="../../gx/dennis/smily.gif" ALT=":-)"
height="24" width="20" align="middle">
</STRONG></P>
<BLOCKQUOTE><IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [Heather]
If any of you kind readers have other interesting ways to make sure your
backups <em>work</em> when you do a restore... their only reason for
existence, after all... let us know!
</BLOCKQUOTE>
<!-- sig -->
<!-- end 23 -->
<!--startcut ======================================================= -->
<P> <hr> </p>
<!-- *** BEGIN copyright *** -->
<H5 align="center">This page edited and maintained by the Editors
of <I>Linux Gazette</I>
<a href="http://www.linuxgazette.com/copying.html"
>Copyright &copy;</a> 2001
<BR>Published in issue 63 of <I>Linux Gazette</I> February Extra 2001</H5>
<H6 ALIGN="center">HTML script maintained by
<A HREF="mailto:star@starshine.org">Heather Stern</a> of
Starshine Technical Services,
<A HREF="http://www.starshine.org/">http://www.starshine.org/</A>
</H6>
<!-- *** END copyright *** -->
<P> <hr>
<!-- begin tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::-->
<p align="center">
<table width="100%" border="0"><tr>
<td align="right" valign="center"
><IMG ALT="" SRC="../../gx/navbar/left.jpg"
WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="middle" border="0">
<A HREF="../lg_answer63.html"
><IMG SRC="../../gx/dennis/answertoc.jpg" align="middle"
ALT="[ Answer Guy Current Index ]" border="0"></A></td>
<td align="center" valign="center"><A HREF="../lg_answer63.html#greeting"><img align="middle"
src="../../gx/dennis/smily.gif" alt="greetings" border="0"></A> &nbsp;
<A HREF="1.html">1</A> &nbsp;
<A HREF="2.html">2</A> &nbsp;
<A HREF="3.html">3</A> &nbsp;
<A HREF="4.html">4</A> &nbsp;
<A HREF="5.html">5</A> &nbsp;
<A HREF="6.html">6</A> &nbsp;
<A HREF="7.html">7</A></td>
<td align="left" valign="center"><A HREF="../../tag/kb.html"
><IMG SRC="../../gx/dennis/answerpast.jpg" align="middle"
ALT="[ Index of Past Answers ]" border="0"></A>
<IMG ALT="" SRC="../../gx/navbar/right.jpg" align="middle"
WIDTH="14" HEIGHT="45" BORDER="0"></td></tr></table>
</p>
<!-- end tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<P> <hr>
<CENTER>
<!-- *** BEGIN navbar *** -->
<!-- *** END navbar *** -->
</CENTER>
</p>
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
</BODY></HTML>
<!--endcut ========================================================= -->