On Monday 02 April 2007, Roger Searle wrote: > My backup script is working really well, even burns some files to a > dvd. I'm impressed (and don't get out much). So of course I now need > to test my backups (like we all do - right?). The problem I am having > is how to then extract the contents of the tar files - all from a script. > > The backup files are all named via a declaration in the initial backup > script, based on date like this: > > TarData=backup-data-`date +%a-%d-%m-%y`.tgz > > and I end up with a file called backup-data-Sun-01-04-07.tgz (similarly > backup-email-Sun-01-04-07.tgz and backup-home-Sun-01-04-07.tgz etc). > > Simple enough to get them copied off the dvd into some folder - mount > the disk, and then cp backup* /pathto/some/folder/. All good up to this > point. I can also extract the contents of the tar files in a similar > way using: > > tar -xvf $TarData > > and this too is all good, I get a restored copy of all my data. But > this only works if it is the run on the same day as the tar file was > made. How can I modify my "tar -xvf" line when I do not know the full > names of my backup files - but do know the first few characters? I > can't simply use wildcards i.e. tar -xvf back*. Google hasn't been > friendly to me today.
Assuming you have the Bash Shell, how about something like:- for tf in `ls backup-*Sun*.tgz` ; do tar xvzf $tf ; done ; use tvzf for the tar options to do a dry run to make sure you have the correct stuff. That will extract all the data in the tar-file for Sunday. remember the -C option to put the data in the required destination directory. The manual page is actually pretty fine. You'd find both the Bash Reference Manual:- http://rholbert.colug.net/pdf/bashref.pdf and the Advanced Bash Scripting guide:- http://tldp.org/LDP/abs/html/ pretty useful. -- CS
