tape rotations and tape autoloaders

Discussion in 'Perl Misc' started by Nix!, Mar 4, 2010.

  1. Nix!

    Nix! Guest

    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?
     
    Nix!, Mar 4, 2010
    #1
    1. Advertising

  2. Nix!

    Nix! Guest

    On Mar 4, 9:39 am, "Nix!" <> wrote:
    > 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. :)
     
    Nix!, Mar 4, 2010
    #2
    1. Advertising

  3. Nix!

    Ted Zlatanov Guest

    On Thu, 4 Mar 2010 06:39:36 -0800 (PST) "Nix!" <> wrote:

    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
     
    Ted Zlatanov, Mar 4, 2010
    #3
  4. Nix!

    Nix! Guest

    On Mar 4, 11:50 am, Don Piven <> wrote:
    > Nix! wrote:
    > > 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.
     
    Nix!, Mar 4, 2010
    #4
  5. Nix!

    Nix! Guest

    On Mar 4, 11:40 am, Ted Zlatanov <> wrote:
    > On Thu, 4 Mar 2010 06:39:36 -0800 (PST) "Nix!" <> wrote:
    >
    > 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.
     
    Nix!, Mar 4, 2010
    #5
  6. On 2010-03-04 16:19, Nix! <> wrote:
    > On Mar 4, 9:39 am, "Nix!" <> wrote:
    >> 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;


    > 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. :)
     
    Peter J. Holzer, Mar 4, 2010
    #6
  7. On 2010-03-04 16:50, Don Piven <> wrote:
    > Nix! wrote:
    >> 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
     
    Peter J. Holzer, Mar 4, 2010
    #7
  8. Nix!

    Nix! Guest

    On Mar 4, 1:47 pm, "Peter J. Holzer" <> wrote:
    > On 2010-03-04 16:19, Nix! <> wrote:
    >
    >
    >
    > > On Mar 4, 9:39 am, "Nix!" <> wrote:
    > >> 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:

    >
    > > #!/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;
    >
    > >         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!
     
    Nix!, Mar 4, 2010
    #8
  9. Nix!

    Nix! Guest

    On Mar 4, 1:55 pm, "Peter J. Holzer" <> wrote:
    > On 2010-03-04 16:50, Don Piven <> wrote:
    >
    > > Nix! wrote:
    > >> 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.
     
    Nix!, Mar 4, 2010
    #9
  10. Nix!

    Ted Zlatanov Guest

    On Thu, 4 Mar 2010 10:45:27 -0800 (PST) "Nix!" <> wrote:

    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
     
    Ted Zlatanov, Mar 4, 2010
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alan
    Replies:
    2
    Views:
    2,140
  2. Charles P Lamb

    SCSI, tape, and scanner I/O?

    Charles P Lamb, Jul 26, 2005, in forum: Java
    Replies:
    0
    Views:
    461
    Charles P Lamb
    Jul 26, 2005
  3. Stylus Studio
    Replies:
    0
    Views:
    387
    Stylus Studio
    Sep 7, 2005
  4. William
    Replies:
    1
    Views:
    452
    Kevin Goodsell
    Sep 9, 2003
  5. Josh Smith

    tarfile and end-of-tape

    Josh Smith, Aug 4, 2003, in forum: Python
    Replies:
    1
    Views:
    330
    Lars Gustaebel
    Aug 5, 2003
Loading...

Share This Page