wiki:manuals/Copying
Last modified 10 years ago Last modified on 11/27/07 16:40:15

This little perl script copies for each directory the current AccessLatency? and RetentionPolicy? to its subdirectories (unless they allready exist).

#!/usr/local/bin/perl -w

# Gives AccessLatency and RetentionPolicy to subdirectory
# if they are not allready set

@ARGV = qw(.) unless @ARGV;
use File::Copy;
use File::Find;

sub setTags {
    return unless -d;
    copy (".(tag)(AccessLatency)", $_) unless (-f "$_/.(tag)(AccessLatency)");
    copy (".(tag)(RetentionPolicy)", $_) unless (-f "$_/.(tag)(RetentionPolicy)");
    print "$File::Find::dir."/$_
"
}

#######################
# Daemonize the process
#

defined(my $pid1 = fork)   or die "Can't fork: $!";
exit if $pid1;
setsid                    or die "Can't start a new session: $!";
   # Second fork
defined(my $pid = fork)   or die "Can't fork: $!";
exit if $pid;

chdir '/'                 or die "Can't chdir to /: $!";
umask 0;
open STDIN, '>/dev/null'   or die "Can't read /dev/null: $!";
open STDOUT, ">>/opt/d-cache/log/pnfs_tagger.out" or die "Can't write to /dev/null: $!";
open STDERR, ">>/opt/d-cache/log/pnfs_tagger.err" or die "Can't write to /dev/null: $!";

#######################

find(&setTags, @ARGV);

Prerequisite :

Set the correct values for each parent directory. The script will handle the subdirectories carefully (not overwriting existing tags)

Illustration :

Before :

data
|-- .(tag)(AccessLatency)          ONLINE
|-- .(tag)(RetentionPolicy)        REPLICA
|-- disk1
|   |-- disk2
|   |   |-- disk3
|   |   `-- tape3
|   |       |-- .(tag)(AccessLatency)          NEARLINE
|   |       `-- .(tag)(RetentionPolicy)        CUSTODIAL
|   |       `-- tape4
|   `-- tape2
|       |-- .(tag)(AccessLatency)          NEARLINE
|       |-- .(tag)(RetentionPolicy)        CUSTODIAL
|       |-- disk3
|       |   |-- .(tag)(AccessLatency)        ONLINE
|       |   `-- .(tag)(RetentionPolicy)      REPLICA
|       `-- tape3
`-- tape1
    |-- .(tag)(AccessLatency)          NEARLINE
    |-- .(tag)(RetentionPolicy)        CUSTODIAL
    |-- disk2
    |   |-- .(tag)(AccessLatency)        ONLINE
    |   |-- .(tag)(RetentionPolicy)      REPLICA
    |   |-- disk3
    |   `-- tape3
    |       |-- .(tag)(AccessLatency)          NEARLINE
    |       |-- .(tag)(RetentionPolicy)        CUSTODIAL
    |       `-- tape4
    `-- tape2
        |-- disk3
        |   |-- .(tag)(AccessLatency)        ONLINE
        |   |-- .(tag)(RetentionPolicy)      REPLICA
        |   `-- disk4
        |       `-- disk5
        `-- tape3

After :

data_after
|-- .(tag)(AccessLatency)        ONLINE
|-- .(tag)(RetentionPolicy)      REPLICA
|-- disk1
|   |-- .(tag)(AccessLatency)        ONLINE
|   |-- .(tag)(RetentionPolicy)      REPLICA
|   |-- disk2
|   |   |-- .(tag)(AccessLatency)        ONLINE
|   |   |-- .(tag)(RetentionPolicy)      REPLICA
|   |   |-- disk3
|   |   |   |-- .(tag)(AccessLatency)        ONLINE
|   |   |   `-- .(tag)(RetentionPolicy)      REPLICA
|   |   `-- tape3
|   |       |-- .(tag)(AccessLatency)          NEARLINE
|   |       |-- .(tag)(RetentionPolicy)        CUSTODIAL
|   |       `-- tape4
|   |           |-- .(tag)(AccessLatency)         NEARLINE
|   |           `-- .(tag)(RetentionPolicy)       CUSTODIAL
|   `-- tape2
|       |-- .(tag)(AccessLatency)         NEARLINE
|       |-- .(tag)(RetentionPolicy)       CUSTODIAL
|       |-- disk3
|       |   |-- .(tag)(AccessLatency)        ONLINE
|       |   `-- .(tag)(RetentionPolicy)      REPLICA
|       `-- tape3
|           |-- .(tag)(AccessLatency)         NEARLINE
|           `-- .(tag)(RetentionPolicy)       CUSTODIAL
`-- tape1
    |-- .(tag)(AccessLatency)
    |-- .(tag)(RetentionPolicy)
    |-- disk2
    |   |-- .(tag)(AccessLatency)        ONLINE
    |   |-- .(tag)(RetentionPolicy)      REPLICA
    |   |-- disk3
    |   |   |-- .(tag)(AccessLatency)        ONLINE
    |   |   `-- .(tag)(RetentionPolicy)      REPLICA
    |   `-- tape3
    |       |-- .(tag)(AccessLatency)         NEARLINE
    |       |-- .(tag)(RetentionPolicy)       CUSTODIAL
    |       `-- tape4
    |           |-- .(tag)(AccessLatency)         NEARLINE
    |           `-- .(tag)(RetentionPolicy)       CUSTODIAL
    `-- tape2
        |-- .(tag)(AccessLatency)         NEARLINE
        |-- .(tag)(RetentionPolicy)       CUSTODIAL
        |-- disk3
        |   |-- .(tag)(AccessLatency)        ONLINE
        |   |-- .(tag)(RetentionPolicy)      REPLICA
        |   `-- disk4
        |       |-- .(tag)(AccessLatency)        ONLINE
        |       |-- .(tag)(RetentionPolicy)      REPLICA
        |       `-- disk5
        |           |-- .(tag)(AccessLatency)        ONLINE
        |           `-- .(tag)(RetentionPolicy)      REPLICA
        `-- tape3
            |-- .(tag)(AccessLatency)         NEARLINE
            `-- .(tag)(RetentionPolicy)       CUSTODIAL

Yeah the illustration was WAAAY longer to wright than the script.

Hoping it comes handy,

Jonathan