Tar: Difference between revisions

adds documentation section
changed to reflect repeated tests showing that tar is safe and doesn't nuke subdirectories
Line 1: Line 1:
The magic tar one-line command to unpack a Drupal distribution over an
The magic tar one-line command to unpack a Drupal distribution over an
existing Drupal directory (without nuking sites) - but keep reading!
existing Drupal directory (without clobbering your "sites" directory)
<source lang="bash">
<source lang="bash">
tar x --show-omitted-dirs --exclude sites --directory ../work/gr/iic-drupal/ \
tar x --show-omitted-dirs --exclude sites --directory ../work/gr/iic-drupal/ \
Line 6: Line 6:
</source>
</source>


--
Drupal ships a tarball with the first object being a directory named
Drupal ships a tarball with the first object being a directory named
after the release (e.g. drupal-6.11/)
after the release (e.g. drupal-6.11/)
Line 26: Line 25:
tar x --directory ~/existing-drupal --strip 1 -zf drupal-6.11.tar.gz
tar x --directory ~/existing-drupal --strip 1 -zf drupal-6.11.tar.gz
</source>
</source>
But wait!! that command will still overwrite your existing "sites"
 
directory which is where you are supposed to store all your
;<code>--strip 1</code> : removes the first path component of objects in the tar archive
customizations to Drupal -- and you don't want to do that.  The
;<code>--directory</code> : tells tar to change to a particular directory prior to extracting the contents of the archive
recommended procedure is to make backups of your "sites" directory and
 
then copy it back into the distribution that you unpack. I think a
If you're upgrading a Drupal instance, then you already have a "sites" directory.   You can skip over this directory in the tar archive with the '''exclude''' option.  In
better way is to skip over the sites directory.  Don't even extract it
from the tar archive.  You can do this with the '''exclude''' option.  In
fact, you can even have tar show you what you have skipped over with
fact, you can even have tar show you what you have skipped over with
the '''show-omitted-dirs''' option.  So, the best way that I know how to
the '''show-omitted-dirs''' option.  So, the best way that I know how to
Line 41: Line 38:
</source>
</source>
This didn't mess with my .git directory, .gitignore file and another
This didn't mess with my .git directory, .gitignore file and another
top-level file I had called "crossdomain.xml" but it still nuked my
top-level file I had called "crossdomain.xml"
"sites" directory :-(
 
== Warning ==
{{Messagebox |
|type=warning
|text = Although I could not reproduce this behavior, I did once get my "sites" directory deleted.  So, you do have [[backups]] and use [[version control]] right?
}}


I restored it with
I restored it with
Line 58: Line 60:


== Documentation ==
== Documentation ==
There is a '''lot''' more option information in the <code>tar --help</code> output
There is a lot more option information in the '''<code>tar --help</code>''' output
than in the man page.  The "info" manual is also online at http://www.gnu.org/software/tar/manual/tar.html providing full documentation for tar.
than in the man page.  Of course if you <code>sudo apt-get install tar-doc</code> then you can view the info manual.  The "info" manual is also online at http://www.gnu.org/software/tar/manual/tar.html providing full documentation for tar.
 
I'll have to test  --keep-newer-files to see if that works.
 
 


== Alternatives ==
== Alternatives ==