tape rotations and tape autoloaders

N

Nix!

Hi everyone,

I have a tape autoloader with 8 tapes. The tapes are labeled monday,
tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.

My backup script needs to be modified to load the correct tape each
friday. A copy of the existing script can be found here:
http://bobotheclown.org/scripts/compperl

Here is the code I have written so far:

#!/usr/bin/perl

use strict;

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
my $tapenumber = --$wday;
my $filename = "/backup/scripts/week_of_month";

if ($wday == 5) {

open FH15,'+<', $filename or die "Could not open $filename: $!\n";
my @weeknumber = <FH15>;
}

my $loadtape = "mtx -f /dev/sg17 load $tapenumber";
print "$loadtape\n";
my $unloadtape = "mtx -f /dev/sg17 unload $tapenumber";
print "$unloadtape\n";

I am presently planning to incriment the week number in a txt file
until it reaches 4 and then start over. This seems fail to me. The
text file may be deleted, and the rotation will be lost. It is also a
lot of code to write.

Can anyone suggest a more intelligent alternative for finding the 1st,
2nd, 3rd, and 4th friday relative to the first time the script ever
ran?
 
N

Nix!

Hi everyone,

I have a tape autoloader with 8 tapes.  The tapes are labeled monday,
tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.

My backup script needs to be modified to load the correct tape each
friday.  A copy of the existing script can be found here:http://bobotheclown.org/scripts/compperl

Here is the code I have written so far:

#!/usr/bin/perl

use strict;

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
my $tapenumber = --$wday;
my $filename = "/backup/scripts/week_of_month";

if ($wday == 5) {

open FH15,'+<', $filename or die "Could not open $filename: $!\n";
my @weeknumber = <FH15>;

}

my $loadtape = "mtx -f /dev/sg17 load $tapenumber";
print "$loadtape\n";
my $unloadtape = "mtx -f /dev/sg17 unload $tapenumber";
print "$unloadtape\n";

I am presently planning to incriment the week number in a txt file
until it reaches 4 and then start over.  This seems fail to me.  The
text file may be deleted, and the rotation will be lost.  It is also a
lot of code to write.

Can anyone suggest a more intelligent alternative for finding the 1st,
2nd, 3rd, and 4th friday relative to the first time the script ever
ran?



heres what I did:

#!/usr/bin/perl

use strict;

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
my $tapenumber = --$wday;
my $filename = "/backup/scripts/week_of_month";

if ($wday == 5) {

open FH15,'<', $filename or die "Could not open $filename: $!
\n";
my @weeknumber = <FH15>;
my $weekscalar = $weeknumber[0];
close FH15;

if ($weekscalar == 1) {
$tapenumber = 5;
$weekscalar++;
} elsif ($weekscalar == 2) {
$tapenumber = 6;
$weekscalar++;
} elsif ($weekscalar == 3) {
$tapenumber = 7;
$weekscalar++;
} elsif ($weekscalar == 4) {
$tapenumber = 8;
$weekscalar = 1;
}

open FH15,'>', $filename or die "Could not open $filename: $!
\n";
print FH15 $weekscalar;
close FH15;
}

my $loadtape = "mtx -f /dev/sg17 load $tapenumber";
print "$loadtape\n";
my $unloadtape = "mtx -f /dev/sg17 unload $tapenumber";
print "$unloadtape\n";


Its ugly but it works, and I can work on something else now. :)
 
T

Ted Zlatanov

N> I have a tape autoloader with 8 tapes. The tapes are labeled monday,
N> tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.

....

N> Can anyone suggest a more intelligent alternative for finding the 1st,
N> 2nd, 3rd, and 4th friday relative to the first time the script ever
N> ran?

If you have a way of finding out what's on each tape (even if it's just
a tape ID) and keeping track, that's a much better way. Then you can
just load the Friday tape with the oldest data. So I would keep a map
of (tape ID => last backup done) and then your script can easily find
the right ID it needs for today.

I would also consider a better backup solution. This is easily handled
by modern backup systems.

Ted
 
N

Nix!

Nix! said:
Hi everyone,
I have a tape autoloader with 8 tapes.  The tapes are labeled monday,
tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.
[...]
I am presently planning to incriment the week number in a txt file
until it reaches 4 and then start over.  This seems fail to me.  The
text file may be deleted, and the rotation will be lost.  It is also a
lot of code to write.

Deleted by who?  Don't forget that in order to control your changer, you
need to be able to write to the device.  Practically speaking, this
means your script has to be executed by the owner of the changer device,
or a user who is a member of a group that has write access to the
device.  On Linux, this usually means that you have to run mtx as root,
or your login id needs to be a member of the "tape" group.  (YMMV.)  So,
why not just restrict access to that text file using the same permissions?

I suppose that if you wanted to be independent and not depend on
anything in or on the filesystem that could be modified, you could take
the number of days since the epoch, divide by 7 to get number of weeks
since the epoch, and use that modulo 4 for your arbitrary week number.
(This might mean your first Friday backup would use "Friday 3", though.)
  You could do something similar using the ctime of your script file as
the baseline, but that's subject to breakage as well if you happen to
copy or move the script file.

Out of curiosity, are you just planning on rotating those four Friday
tapes without regard to month boundaries?  If you want "Friday 1" to
correspond to the first Friday of the month, better rethink your
rotation strategy because it'll bite you on the butt this upcoming April
30, which is the 5th Friday of the month.

I use the grandfather son strategy modified for 5 days a week instead
of 7. That is why I didnt want to use dates as a key. Over the four
friday rotation, at the end of 365 days I will have used 20 tapes + 1
annual (remembering that I never overwrite a friday 4) It doesnt
really matter when I begin as it is based on 365 days.

By doing it this way I will be able to recover from any day this week,
any week this month, any month this year, or any year since the sytem
has been in operation.

Thank you very much for your advice.
 
N

Nix!

N> I have a tape autoloader with 8 tapes.  The tapes are labeled monday,
N> tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.

...

N> Can anyone suggest a more intelligent alternative for finding the 1st,
N> 2nd, 3rd, and 4th friday relative to the first time the script ever
N> ran?

If you have a way of finding out what's on each tape (even if it's just
a tape ID) and keeping track, that's a much better way.  Then you can
just load the Friday tape with the oldest data.  So I would keep a map
of (tape ID => last backup done) and then your script can easily find
the right ID it needs for today.

I would also consider a better backup solution.  This is easily handled
by modern backup systems.

Ted

Great idea Ted. Im gonna chase this down. Sorry everyone for getting
off perl code.
 
P

Peter J. Holzer

I have a tape autoloader with 8 tapes.  The tapes are labeled monday,
tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.

My backup script needs to be modified to load the correct tape each
friday.  A copy of the existing script can be found here:http://bobotheclown.org/scripts/compperl [...]
I am presently planning to incriment the week number in a txt file
until it reaches 4 and then start over.  This seems fail to me.  The
text file may be deleted, and the rotation will be lost.  It is also a
lot of code to write.

Can anyone suggest a more intelligent alternative for finding the 1st,
2nd, 3rd, and 4th friday relative to the first time the script ever
ran?



heres what I did:

#!/usr/bin/perl

use strict;

use warnings;

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
my $tapenumber = --$wday;
my $filename = "/backup/scripts/week_of_month";

if ($wday == 5) {

open FH15,'<', $filename or die "Could not open $filename: $!
\n";

Use lexical filehandles:

open my $fh15, '<', $filename or die "Could not open $filename: $!";

(and find a better name than "$fh15", e.g. $week_fh)
my @weeknumber = <FH15>;
my $weekscalar = $weeknumber[0];

These two lines can be replaced with

my $weekscalar = <FH15>;

but you should also add a

chomp($weekscalar);

to remove the trailing newline (and avoid a warning).
close FH15;

if ($weekscalar == 1) {
$tapenumber = 5;
$weekscalar++;
} elsif ($weekscalar == 2) {
$tapenumber = 6;
$weekscalar++;
} elsif ($weekscalar == 3) {
$tapenumber = 7;
$weekscalar++;
} elsif ($weekscalar == 4) {
$tapenumber = 8;
$weekscalar = 1;
}

This whole if/elsif block can be replaced with:

$tapenumber = $weekscalar + 4;
$weekscalar = $weekscalar % 4 + 1;
 
P

Peter J. Holzer

Nix! said:
Hi everyone,

I have a tape autoloader with 8 tapes. The tapes are labeled monday,
tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.
[...]
I am presently planning to incriment the week number in a txt file
until it reaches 4 and then start over. This seems fail to me. The
text file may be deleted, and the rotation will be lost. It is also a
lot of code to write.
[...]
I suppose that if you wanted to be independent and not depend on
anything in or on the filesystem that could be modified, you could take
the number of days since the epoch, divide by 7 to get number of weeks
since the epoch, and use that modulo 4 for your arbitrary week number.

Alternatively you could use the number of the week in the current year:

$tapenumber = strftime("%V", localtime) % 4;

However, every few years the first backup of the year will overwrite the
last backup of the previous year (when the last week is week 53, not
week 52), so your method is probably preferable.

hp
 
N

Nix!

I have a tape autoloader with 8 tapes.  The tapes are labeled monday,
tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.
My backup script needs to be modified to load the correct tape each
friday.  A copy of the existing script can be found here:http://bobotheclown.org/scripts/compperl [...]
I am presently planning to incriment the week number in a txt file
until it reaches 4 and then start over.  This seems fail to me.  The
text file may be deleted, and the rotation will be lost.  It is alsoa
lot of code to write.
Can anyone suggest a more intelligent alternative for finding the 1st,
2nd, 3rd, and 4th friday relative to the first time the script ever
ran?
heres what I did:

use strict;

use warnings;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
my $tapenumber = --$wday;
my $filename = "/backup/scripts/week_of_month";
if ($wday == 5) {
        open FH15,'<', $filename or die "Could not open $filename: $!
\n";

Use lexical filehandles:

    open my $fh15, '<', $filename or die "Could not open $filename: $!";

(and find a better name than "$fh15", e.g. $week_fh)
        my @weeknumber = <FH15>;
        my $weekscalar = $weeknumber[0];

These two lines can be replaced with

        my $weekscalar = <FH15>;

but you should also add a

        chomp($weekscalar);

to remove the trailing newline (and avoid a warning).
        close FH15;
                if ($weekscalar == 1)   {
                        $tapenumber = 5;
                        $weekscalar++;
                } elsif ($weekscalar == 2)      {
                        $tapenumber = 6;
                        $weekscalar++;
                } elsif ($weekscalar == 3)      {
                        $tapenumber = 7;
                        $weekscalar++;
                } elsif ($weekscalar == 4)      {
                        $tapenumber = 8;
                        $weekscalar = 1;
                }

This whole if/elsif block can be replaced with:

                $tapenumber = $weekscalar + 4;
                $weekscalar = $weekscalar % 4 + 1;
        open FH15,'>', $filename or die "Could not open $filename: $!
\n";
        print FH15 $weekscalar;
        close FH15;
}
my $loadtape = "mtx -f /dev/sg17 load $tapenumber";
print "$loadtape\n";
my $unloadtape = "mtx -f /dev/sg17 unload $tapenumber";
print "$unloadtape\n";
Its ugly but it works, and I can work on something else now.  :)

I knew there was a better way. This is sexy. For some reason I
thought if I read a filehandle into a scalar I would only get the
number of elements. I was prolly smoking crack that day. Thanks a
lot!
 
N

Nix!

Nix! said:
Hi everyone,
I have a tape autoloader with 8 tapes.  The tapes are labeled monday,
tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.
[...]
I am presently planning to incriment the week number in a txt file
until it reaches 4 and then start over.  This seems fail to me.  The
text file may be deleted, and the rotation will be lost.  It is alsoa
lot of code to write.
[...]
I suppose that if you wanted to be independent and not depend on
anything in or on the filesystem that could be modified, you could take
the number of days since the epoch, divide by 7 to get number of weeks
since the epoch, and use that modulo 4 for your arbitrary week number.

Alternatively you could use the number of the week in the current year:

$tapenumber = strftime("%V", localtime) % 4;

However, every few years the first backup of the year will overwrite the
last backup of the previous year (when the last week is week 53, not
week 52), so your method is probably preferable.

        hp
Thanks hp.
 
T

Ted Zlatanov

N> I use the grandfather son strategy modified for 5 days a week instead
N> of 7. That is why I didnt want to use dates as a key. Over the four
N> friday rotation, at the end of 365 days I will have used 20 tapes + 1
N> annual (remembering that I never overwrite a friday 4) It doesnt
N> really matter when I begin as it is based on 365 days.

N> By doing it this way I will be able to recover from any day this week,
N> any week this month, any month this year, or any year since the sytem
N> has been in operation.

Sorry to get off-topic, but most backup strategies use incrementals or
differentials in addition to full backups. If your goal is to do full
recovery, consider daily differentials from Friday and a full backup
every Friday. That gives you redundancy (Monday's changes will also be
on Tuesday's tape) without using so many tapes. The nice thing about
full backup solutions is that you'd label your tapes, throw them in a
jukebox, and just assign them to a pool. Then the software will look in
the pool and figure out if it has a tape that's blank, can be recycled,
etc.

You could also consider something like this:

http://www.blackpepper.co.uk/black-pepper-blog/Using-Amazon-EC2-EBS-S3-for-automated-backups.html

Ted
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top