Tar: Difference between revisions
No edit summary |
m Text replacement - "<(\/?)source" to "<$1syntaxhighlight" |
||
| Line 4: | Line 4: | ||
=== Get just one file === | === 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: | <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: | ||
< | <syntaxhighlight lang="bash"> | ||
# look at what's in the archive | # look at what's in the archive | ||
tar -tf ~/drush-backups/archive-dump/20150327030955/freephile_drupal.20150327_030955.tar | 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) | # 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 | tar -xf ~/drush-backups/archive-dump/20150327030955/freephile_drupal.20150327_030955.tar freephile_drupal.sql | ||
</ | </syntaxhighlight> | ||
=== Strip top level of the archive and don't extract a sub-folder === | === 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 | The magic tar one-line command to unpack a Drupal distribution over an | ||
existing Drupal directory (without clobbering your "sites" directory) | existing Drupal directory (without clobbering your "sites" directory) | ||
< | <syntaxhighlight 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/ \ | ||
--strip 1 -zf drupal-6.11.tar.gz | --strip 1 -zf drupal-6.11.tar.gz | ||
</ | </syntaxhighlight> | ||
Drupal ships a tarball with the first object being a directory named | Drupal ships a tarball with the first object being a directory named | ||
| Line 35: | Line 35: | ||
But, if you want to do it all in one pass, you can use the combination | But, if you want to do it all in one pass, you can use the combination | ||
of '''strip''' and '''directory''' options: | of '''strip''' and '''directory''' options: | ||
< | <syntaxhighlight lang="bash"> | ||
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 | ||
</ | </syntaxhighlight> | ||
;<code>--strip 1</code> : removes the first path component of objects in the tar archive | ;<code>--strip 1</code> : removes the first path component of objects in the tar archive | ||
| Line 47: | Line 47: | ||
unpack a Drupal archive over an existing installation - all in one | unpack a Drupal archive over an existing installation - all in one | ||
easy command - is | easy command - is | ||
< | <syntaxhighlight lang="bash"> | ||
tar x --show-omitted-dirs --exclude sites --directory ../work/gr/iic-drupal/ --strip 1 -zf drupal-6.11.tar.gz | tar x --show-omitted-dirs --exclude sites --directory ../work/gr/iic-drupal/ --strip 1 -zf drupal-6.11.tar.gz | ||
</ | </syntaxhighlight> | ||
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" | top-level file I had called "crossdomain.xml" | ||
| Line 60: | Line 60: | ||
I restored it with | I restored it with | ||
< | <syntaxhighlight lang="bash"> | ||
git checkout sites | git checkout sites | ||
</ | </syntaxhighlight> | ||
and then I did a | and then I did a | ||
< | <syntaxhighlight lang="bash"> | ||
git status | git status | ||
</ | </syntaxhighlight> | ||
followed by | followed by | ||
< | <syntaxhighlight lang="bash"> | ||
git commit -a -m 'adds changes in Drupal 6.11 security release' | git commit -a -m 'adds changes in Drupal 6.11 security release' | ||
</ | </syntaxhighlight> | ||
== Documentation == | == Documentation == | ||
| Line 84: | Line 84: | ||
from | from | ||
http://www.cs.toronto.edu/~murray/code/hacks/untar | http://www.cs.toronto.edu/~murray/code/hacks/untar | ||
< | <syntaxhighlight lang="bash"> | ||
#!/bin/bash | #!/bin/bash | ||
| Line 347: | Line 347: | ||
fi | fi | ||
done | done | ||
</ | </syntaxhighlight> | ||
== See Also == | == See Also == | ||