Showing posts with label gzip. Show all posts
Showing posts with label gzip. Show all posts

How to Extract Specific Directory from Tarball

Tags: September 24, 2016 9:30 PM
0 comments

Problem

We have huge file of gzipped tarball and we want to extract only specific directory from the tarball.

Solution

Make sure the pattern we want to extract by searching it first. As an example we want to extract directory named johndoe-website, but we did not know the full pattern of the directory.

$ tar tvf the-archive.tar.gz | grep johndoe-website
home/sites/clients/johndoe-website/javascripts/main.js
home/sites/clients/johndoe-website/styles/main.css
home/sites/clients/johndoe-website/index.html
From the output above we knew that the pattern of the directory is home/sites/clients/johndoe-website. Command below will extract johndoe-website from the archive and strip the 3 leading directories.
$ tar xvf the-archive.tar.gz --strip-components=3 -C /destination/path home/sites/clients/johndoe-website
Command above works in GNU Tar and BSD Tar (Mac OS X).

Share on Facebook Twitter

Compressing mysqldump output with gzip

Tags: April 29, 2012 2:52 PM
0 comments

Compressing mysqldump ouput is a good practice since your sql dump file could be very big. The good thing is the result of the dump is in plain text, so tools such gzip can siginificanly reduce the size.

# mysqldump -u username -ppassword databasename | gzip > dbname.sql.`date +%Y-%m-%d_%H%M%S`.gz
Put it to cron for daily backup. Cron treat '%' as special character so it needs to be escaped.
0 0 * * * mysqldump -u username -ppassword databasename | gzip > dbname.sql.`date +\%Y-\%m-\%d_\%H\%M\%S`.gz

Share on Facebook Twitter