Open main menu

Changes

1,739 bytes added ,  00:26, 29 March 2015
no edit summary
GNU Tar is everybody's favorite archive file format.
 
== Use Cases ==
=== Get just one file ===
<code>drush archive-backup (arb)</code> and <code>drush archive-restore (arr)</code> are great commands for making a full site backup prior to changes; that you can use to restore from. Your entire Drupal instance (code, settings, modules, plus database) are all tar'd into an archive file, and gzip compressed <ref>The example refers to a .tar file. <code>drush archive-backup</code> creates a .tar.gz file -- meaning it's compressed with gzip. So, to work with the .tar file, first you would uncompress the .tar.gz file with <code>gunzip file.tar.gz</code></ref>. Again, one of the things that <code>drush arb</code> does is create a SQL dump file. What if you want just that dump file from the archive? The long way would be to extract the whole thing, find and move the bits you want, and then discard the rest. Or, you could just tell tar to give you the file you want explicitly:
<source lang="bash">
# look at what's in the archive
tar -tf ~/drush-backups/archive-dump/20150327030955/freephile_drupal.20150327_030955.tar
# request just the SQL dump file (puts it into the current working directory)
tar -xf ~/drush-backups/archive-dump/20150327030955/freephile_drupal.20150327_030955.tar freephile_drupal.sql
</source>
 
=== Strip top level of the archive and don't extract a sub-folder ===
The magic tar one-line command to unpack a Drupal distribution over an
existing Drupal directory (without nuking clobbering your "sites" directory) - but keep reading!
<source lang="bash">
tar x --show-omitted-dirs --exclude sites --directory ../work/gr/iic-drupal/ \
</source>
--
Drupal ships a tarball with the first object being a directory named
after the release (e.g. drupal-6.11/)
tar x --directory ~/existing-drupal --strip 1 -zf drupal-6.11.tar.gz
</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 archivecustomizations to Drupal ;<code>-- and you don't want directory</code> : tells tar to change to do that. Therecommended procedure is a particular directory prior to make backups extracting the contents of your the archive If you're upgrading a Drupal instance, then you already have a "sites" directory andthen copy it back into the distribution that you unpack. I think abetter way is to You can skip over the sites this directory. Don't even extract itfrom in 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
the '''show-omitted-dirs''' option. So, the best way that I know how to
</source>
This didn't mess with my .git directory, .gitignore file and another
top-level file I had called "crossdomain.xml" but it still nuked  == 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
== Documentation ==
There is a '''lot''' more option information in the '''<code>tar --help</code> ''' outputthan 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 ==
done
</source>
 
== See Also ==
Sometimes you end up with a directory nested in it's intended destination (like drush arb can leave you with /var/www/drupal/drupal). See the [[Bash]] article for moving a nested directory up a level.
 
{{References}}
4,558

edits