benjamin brumaire

IT - architect
Security • Solaris • Infosystems

 
please select your language  


28/11/06

Too much good leads to bad (part 2)

I wrote why too much tricks could leads to unexpected behaviors here. Facing some corrupted tar archive, some requirements are needed in order to repair them successfully:

  • programming skills
  • knowledge on how the corruption occured
  • basic informations on tar format
  • times
  • perseverance

Given my affinity for perl the choice was obvious. In fact perl fits pretty well in strings processing (scoop).
The relevant part on tar format can be found in the manual pages archives(4)


#define TBLOCK 512 /* length of tar header and data blocks */

For the record I 'll put my code in a simplify version. Through trial&error it is necessary to expand the regular expression section to match all intruders.


#!/usr/local/bin/perl

my $file=$ARGV[0];
my $new_file=$ARGV[1];
my $akt_pos=0;
my $record="";
my $size_buf=1024;
my $eof=0;

open (FH,"<$file") or die "Couldn't open file $file\n";
open (FH_NEW,">$new_file") or die "Couldn't open file $new_file\n";

until ( eof(FH)){
if (length($record) < $size_buf) {
$akt_pos = tell (FH);
if (read (FH,$txt, $size_buf-length($record)) == $size_buf-length($record)){
$record.=$txt;
} else {
seek(FH,$akt_pos,0);
while ((read(FH,$txt,1) == 1)){
$record .= $txt;
$eof=1;
}
}
} else {
$c=0;
}
$txt = $record;
$record =~ s/a \.\/somepath\/.* \d+K\n//mg;
$record =~ s/a .* symbolic link to .*\n//mg;
$record =~ s/a \.\/somepath\/.* excluded\n//mg;
if ( ! $eof ) {
if ( $record eq $txt ) {
if (length($record) == $size_buf) {
printf (FH_NEW "%.512s",$record);
$record=substr($record,512);
}
}
} else {
printf (FH_NEW "%s", $record);
}
}
close(FH);
close(FH_NEW);

On a last note, I would recommend using star as an improved version over many tar implementation including GNU tar and stock Solaris version.
bbr

Permalink
Categories: , Solaris, 08:46:47 am274 words   English (US)

Too much good leads to bad

Each cook knows it for sure, don't follow the "too much" path if you want to succeed. This rule can although be applied to computer. Take UNIX, it is a real cool OS. You can do art on the command line, piping tools together, using complex regular expression,... As a technogeek working on leading edge projects it might be ok but as sysadmin for a bank it is probably plain wrong. Just keep things simple.

What's wrong with tar, gzip and nohup

tar is used to create archive. It is a very usefull utility, well known and in UNIX for years. If you want to create an archive you provide a filename or a device where it will be create. After that you can compress it with gzip to save some space. Supposed you want to archive a lot of files, depending on I/O performance it can take hours. It is then a good practice to use nohup to stay imune to HUP signal. Put this 2 lines (tar and gzip) in a script, start it with nohup and you are fine...
unless you want too much good. Of course (and it is not new) you can use dash instead of filename within tar. It will then write your archive on STDOUT which you can redirect through pipe to gzip. Put nohup in front of it. You have now a much more elegant one liner doing exactly the same.
Not quite.
The man page for nohup state
"If nohup.out is not writable in the current directory, out-
put is redirected to $HOME/nohup.out. If a file is created,
the file will have read and write permission (600, see
chmod(1)). If the standard error is a terminal, it is
redirected to the standard output, otherwise it is not
redirected. The priority of the process run by nohup is not
altered."
OUTCH
Unfortunatly tar writes progress messages on STDERR. This will under certain circonstances corrupts the tarfile, making it completely needless!
If you have this kind of story I'll be glad to hear from it. Next article will deal with the recovery process from a 80 GB corrupted tar archive.
bbr

Permalink
Categories: , Solaris, 08:05:31 am359 words   English (US)

certified

The result arrived over the weekend and guess what I
passed. Call me SCSA :)
After 15+ years experience with Solaris, everyone should pass the test "mit links" or "les doigts dans le nez" but indeed those tests didn't say much. You've well prepared the exam, you 've enough money and time to take the trainings. Companies should't make their mind and shouldn't choose employes or consultants based on certification.
But reality is quiet different as nowadays employe-time is very expensive! Only
few companies are willing to spend money for recruiting and managing human ressources. Certification is then some kind of insurance.
Anyway now that I'm on my own, I've to play the game.

bbr

Permalink
Categories: , Solaris, 07:58:04 am113 words   English (US)

 

 

 

 

cultural exception

September 2010
Mon Tue Wed Thu Fri Sat Sun
<<  <   >  >>
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      

Search

Categories

cultural exception


Archives

Syndicate this blog XML

What is RSS?

Misc

powered by
b2evolution