Used Tapes of a Sesam Day

From SEPsesam
Jump to: navigation, search

Copyright © SEP AG 1999-2020. All rights reserved.

Any form of reproduction of the contents or parts of this manual is allowed only with the express written permission from SEP AG. When compiling and designing user documentation SEP AG uses great diligence and attempts to deliver accurate and correct information. However, SEP AG cannot issue a guarantee for the contents of this manual.

Introduction

It may be helpful to get an overview of all media used for backups, for specific media pools (primarily tape media), at the end of a Sesam day. Therefore, the following script can be used. If the script is called without specifying a Sesam day the current Sesam day is used.


Configuration

  • First, copy the source code below to a file in Linux (e.g. List_Used_Media.sh). In case of Windows the file could be called List_Used_Media.ps1 for example.
  • Then copy this file to /opt/sesam/bin/sesam respectively to <sesam-root>\bin\sesam
  • Don't forget to make that file executable on Linux:
chmod +x /opt/sesam/bin/sesam/List_Used_Media.sh
  • The script can be integrated into SEP sesam in 2 different ways.


A: as a Command event

1. In the SEP sesam GUI a schedule (e.g. output_used_media) can be created to define when this script should run (e.g. "At 07:30 from Monday to Friday").

2. A command event is attached to this schedule. For this the schedule is highlighted and selected using the right mouse button. Select the entry command event in the menu.

3. With the drop-down box Name a pre-existing command is selected.


UsedTapes CmdEvent empty.jpg


4. Because the command does not exist, use the button list and in the new dialog with the button new create a new command. Configure it as shown in the image.


UsedTapes Cmd en.jpg


After completing the command configuration confirm the command with the Use button and close the dialog with <OK>. Now the command event is configured.


UsedTapes CmdEvent en.jpg


In addition to the scheduled use it is possible to start this command manually. This can be done by selecting Activities / Immediate Start / Command in the SEP sesam GUI main menu.


UsedTapes Start.jpg


Using the button White arrow in green circle shows a command list from which the desired command can be selected. The command is copied into the edit field where it can be changed if required and is then taken over <OK> as immediate start.


B: as a command of All_Jobs_Done event for the sm_notify interface

Extract from sm_notify (Linux):

...
case $1 in
      ALL_JOBS_DONE)
         /opt/sesam/bin/sesam/list-used-labels.sh
         send_status_mail "$2";
         # unload_tape 2;
         ;;
      INIT)
...

Extract from sm_notify.ps1 (Windows):

switch($command){
  ALL_JOBS_DONE {$mail_subject = "Sesam backup status: $message"
					mail_attach $mail_subject;
					./List_Used_Media.ps1;
					#print_attach;
					#unload_tape 2;
					#load_to_slot 1 2;
                	break}

That means the script will executed after the last planned event of the Sesam day has been finished.

Source

Linux

  • If no date is given, the current Sesam day is used.
  • This example shows used media for media pools Day, Week, Month and VMs. Replace the values in the array MPOOLS with mediapool names of your Sesam environment.
#!/bin/bash
#####################################################################
#
# Output of tape media that were used at the specified Sesamday for 
# backup. If no date is specified, the current Sesamday is set.
#
#####################################################################

MPOOLS="'Day','Week','Month','VMs'"
OUTFILE="/tmp/Used-Sesam-Media.txt"

read_ini()
{
  source `grep -i '^sm_ini=' /etc/sesam2000.ini|cut -d"=" -f2` 2>/dev/null
}

read_ini
source "${gv_rw_ini}/sesam2000.profile" >/dev/null 2>&1

DATEVALID=0

if [ "$1" == "" ]; then   # determine last Sesam day
  SESAMDAY=`sm_db "select max(sesam_date) from results" | tail -1 | cut -d"=" -f3 | cut -d" " -f1`
  DATEVALID=1
elif [[ "$1" =~ \([[:digit:]]\{4\}-[[:digit:]]\{2\}-[[:digit:]]\{2\}\) ]];then  # Dateformat OK?
    SESAMDAY=$1
    DATEVALID=1
else
  echo "Wrong date format !! Indicate date with pattern yyyy-mm-tt."
  exit 1
fi

if [ $DATEVALID -ne 0 ]; then
  echo "Following media were used for backup on Sesamday <$SESAMDAY>:" | tee $OUTFILE
  sm_db "SELECT label,barcode FROM media WHERE label IN (SELECT DISTINCT label FROM result_lbls WHERE saveset IN (SELECT saveset FROM results WHERE state IN  ('0','1') AND sesam_date LIKE '$SESAMDAY%' AND media_pool IN ($MPOOLS)))" | tee -a $OUTFILE
  sm_smtp -A "sesam" -s "SEP sesam Msg: Used media on Sesamday <$SESAMDAY>" -M "$OUTFILE"
  RC=$?
fi

if [ $RC -eq 0 ]; then
  echo STATUS=SUCCESS MSG="Media list was successfully created and sent by email."
else
  echo STATUS=ERROR MSG=Error during processing
fi

Windows

This is a Powershell Script. To execute a Powershell script you have set the permissions on the server. For detailed information see: FAQ


#################################################
#						#
# Printout of used media of specific sesam day.	#
# With empty parameter use current sesam day.	#
#						#
#################################################



if([string] $args[0] -eq "")	# Check, whether first parameter is a date
{
	# Use current sesam day, if no parameter was specified
	$SESAMDAY = (sm_glbv r gv_datum) + " 00:00:00"
}
else
{
	if($args[0] -match "^\d{4}\-\d{2}\-\d{2}$") # Check, whether date is in correct format
	{
		$SESAMDAY = $args[0] + " 00:00:00"
	}
	else
	{
		# Inform user of wrong date format and quit program
		write "Wrong date format, please use format yyyy-mm-tt"
		return
	}
}

# select all necessary data
$RESULT = ([string] (sqlite3 -noheader "$(sm_glbv r gv_rw_db)\sesam_db.sdb" "select label from media where label IN (select distinct label from result_lbls where saveset in (select saveset from results where sesam_date='$($SESAMDAY)' and blocks>0)) order by pool,label")).Split()

# In case of no result(s)
if($RESULT.Length -lt 1)
{
	sm_smtp -A sesam -s "SESAM: No media found" -m " No media found for specified sesam day $(($SESAMDAY).Replace(' 00:00:00','')). Either the date is wrong or no backup ran this date"
	return
}

# count variable
$count=0

# Write text into a file temporarily 
Set-Content -Path $Env:TEMP\labels.txt -Value ("Following tapes were used for backups on sesam day $(($SESAMDAY).Replace(' 00:00:00','')):")

# Loop to write each medium in a new line
while($count -le $RESULT.Length)
{
	if ( ($RESULT)[$count] -match "^\w{6,}" )
	{
        Add-Content -Path $Env:TEMP\labels.txt -Value "Label: $($RESULT[$count])"
	}
	$count++;
}

# send mail
sm_smtp -A sesam -s "SESAM: Overview of used media" -M $env:TEMP\labels.txt