Let's say you have a deep folder structure and you want to retain that structure but only include a certain subset of file types, how you gonna do that?
Here's a really simple example of how to create a tar that :-
Retains the folder structure of the source data
tar.gz Filename must contain the date
Must be a re-usable bash command that could be used via
Here's the Command Well one way to skin this cat!
now=$(date +"%m_%d_%Y"); find . -name "*.xml" | tar -cvzf ../../data-v1.03.rc1-$now.tar.gz -T -
Breaking it down there are 3 commands used :
date & bash var
First of all we store the date formatted into a var
You can check the format within the
now varible via :
$ echo $now
find & pipe the files
find we print, via stdOut, the files and paths that match the search term.
find . -name "*.xml"
These are then piped via the
| (pipe) char to the
tar the stdIn
Now we take the list of files found via
find and using the
-T - switches of
via stdOut of
find to stdIn of
Using the var
$now generated earlier we create a filename that contains todays
tar -cvzf ../../data-v1.03.rc1-$now.tar.gz -T -
Please note the importantace of the trailing
-, a few times I've been confused
by ommiting it.
You can see how easy it is to generate a command that will generate a tar.gz file
with only the data we're interested in.
Combine this with a
crontab setup you have, albeit quick crude and simple,
a very resiliant backup solution.
More File Types
If you wanted to included, say,
.jpg or .
png file type too simply modify the
find command to :
find . -name "*.xml" -o -name '*.jpg' -o -name '*.png'
What I'm using
find . -name "*.xml" -o -name '*.jpg' -o -name '*.png' -o -name '.ico' -o -name '.pdf' | \
tar -cvzf ../data-v1.03.LIVE-$now.tar.gz -T -