Gitlab Community Edition Instance
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bnachtw
TSM-Scripts
Commits
88e21533
Commit
88e21533
authored
Oct 29, 2020
by
bnachtw
Browse files
initial coding for scripted_container_mode.pl -- seems to work ;-)
parent
92a1e031
Changes
1
Hide whitespace changes
Inline
Side-by-side
Server-Maintainance/scripted_container_move.pl
0 → 100644
View file @
88e21533
#! /usr/bin/perl
##############################################################################
#
# scripted-container_move.pl
#
# script for identifying sparse containers and moving their data
#
#
# (C) 2020 GWDG Goettingen, Bjørn Nachtwey
# mailto:bjoern.nachtwey@gwdg.de
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#
# changelog
# date version remark
# 2020-10-28 0.1 initial coding
#
##############################################################################
use
warnings
;
use
strict
;
use
Time::
Piece
;
##############################################################################
# check for necessary arguments
##############################################################################
if
(
$#ARGV
!=
6
)
{
printf
"
\n\t
usage:
\n\n\t
";
printf
"
perl -f scripted-container_move.pl <Admin-UID> <Admin-PW> <Ratio of Free data> <Days since last write> <servername as in dsm.sys> <directory to move to>
";
printf
"
\n\n
";
exit
99
;
}
##############################################################################
##############################################################################
# F I L L I N Y O U R S E T T I N G S H E R E
##############################################################################
##############################################################################
##############################################################################
# C R E D E N T I A L S
##############################################################################
my
$admuser
=
$ARGV
[
0
];
# or replace by expicit ID
my
$admpwd
=
$ARGV
[
1
];
# or replace by expicit PW
##############################################################################
# R U N T I M E S E T T I N G S
##############################################################################
my
$utillimit
=
$ARGV
[
2
];
# ratio of utilization
my
$dayslimit
=
$ARGV
[
3
];
# limit of days for last write access
my
$entrylimit
=
$ARGV
[
4
];
# limit of entries to be moved
my
$servername
=
$ARGV
[
5
];
# servername
my
$destdir
=
$ARGV
[
6
];
# destination stgpooldir
##############################################################################
# O U T P U T S E T T I N G S
##############################################################################
my
$date
=
localtime
->
strftime
('
%F
');
my
$outputpath
=
"
/TSM/log/
"
.
$date
.
"
-
$servername
-containermove.log
";
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# set some variables
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my
$dsmadmc
=
"
/usr/bin/dsmadmc
";
# linux servers
my
$dsmadsmargs
=
"
-tab -dataonly=yes -id=
$admuser
-pa=
$admpwd
-outfile
";
# # some lists to be processed
my
@result
;
# return of select
my
@containerlist
;
# list of containers eligable for MOVE
# # some loop iterators
my
$thiscontainer
;
my
$container_name
;
# name of actual container
my
$dataamount
;
# amount of data stored on actual container
my
$freeamount
;
# amount of free space on actual container
# for logging
my
$time
=
localtime
->
strftime
('
%R
');
my
$global_freeamount
;
# amount of space freed by moving
# # new variables
my
$command
;
# put system command in seperate variable for debugging
my
$selectstatement
;
# .. same with building select statements :-)
my
$rc_test
;
# test for return code of command
open
LOGFILE
,
"
>>
"
.
$outputpath
or
die
"
$0 cannot open log file:
"
.
$outputpath
;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# main routine
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$selectstatement
=
"
select CONTAINER_NAME, CAST(FLOAT(FREE_SPACE_MB / TOTAL_SPACE_MB ) AS DEC (5,4)) AS PCT, FREE_SPACE_MB, TOTAL_SPACE_MB
"
.
"
from containers where
"
.
"
( state='AVAILABLE' and (FREE_SPACE_MB / TOTAL_SPACE_MB)>
$utillimit
and (DAYS(current_date) - DAYS(LASTWR_DATE))>
$dayslimit
)
"
.
"
order by pct desc limit
$entrylimit
";
$command
=
"
$dsmadmc
$dsmadsmargs
-se=
$servername
\"
$selectstatement
\"
2>/dev/null
";
@containerlist
=
split
'
\n
'
,
`
$command
`;
if
(
!
@containerlist
)
{
printf
LOGFILE
"
%s: nothing to do!
\n
",
$time
;
close
LOGFILE
;
exit
0
;
}
else
{
container:
foreach
$thiscontainer
(
@containerlist
)
{
printf
"
>>%s
\n
",
$thiscontainer
;
if
(
(
$thiscontainer
=~
m/^ANR/
)
or
(
$thiscontainer
=~
m/^ANS/
)
)
{
last
container
;
}
else
{
(
$container_name
,
undef
,
$freeamount
,
$dataamount
)
=
split
'
',
$thiscontainer
;
# move data
$command
=
"
$dsmadmc
$dsmadsmargs
-se=
$servername
\"
move container
$container_name
STGPOOLDIRectory=
$destdir
\"
2>/dev/null
";
@result
=
split
'
\n
'
,
`
$command
`;
$rc_test
=
grep
(
/Return/
,
@result
);
if
(
$rc_test
==
0
)
{
printf
LOGFILE
"
%s: move data %s (saving %7.2f GB)
\n
",
$time
,
$container_name
,
$freeamount
;
}
}
}
}
close
LOGFILE
;
exit
0
;
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment