ADSM-L

Re: Script attached to archive a directory on AIX

2003-03-06 10:27:53
Subject: Re: Script attached to archive a directory on AIX
From: Hamish Marson <hamish AT TRAVELLINGKIWI DOT COM>
To: ADSM-L AT VM.MARIST DOT EDU
Date: Thu, 6 Mar 2003 15:27:12 +0000
Miles Purdy wrote:

Hi folks, thought I'd give back a little,

we have many directories on our UNIX servers that contain application 
development code, some of it is very old of course. And of course we can't just 
delete it. So I wanted a quick a dirty way to save it to TSM. I wrote a little 
script that archives a directory (and sub dirs) to TSM and leaves a script in 
the directory to do the restore, so you don't have to look very hard when you 
need the files.

Have a look at the script if you think this could help you. You will have to 
change the default archive management class. I made one called 'forever' (which 
is 9999 days). Please test it before you run it on your production servers! Be 
careful which input directory you use also, the script runs a 'rm -r 
$DIRECTORY/*'.

These are the key lines of code:
# archive it
dsmc arch -archmc=$ARCHMC -desc="$DIRECTORY $DATE" ${DIRECTORY}/
# delete it
rm -r ${DIRECTORY}/*
#make a script
echo dsmc retrieve -desc=\"$DIRECTORY $DATE\" ${DIRECTORY}/             
>$OUT_FILE

Miles





You might want to change the line

if [[ $DIRECTORY = '/' || $DIRECTORY = '/usr' || $DIRECTORY = '/etc' || 
$DIRECTORY = '/var' ||



to include ("${DIRECTORY} = "")

as well to catch a NULL (Implied root)


H

#!/usr/bin/ksh
#
# Name: archive_directory
#
# Purpose: Will send a directory and all its subdirectories to TSM, to save 
disk space,
#          leaving a script to restore the directory.
#
# Date: 5 Mar 2003
#
# Required Parameters:
# -------------------------------------------------------------------------
# Directory - the full path of the directory to archive
#
# Optional Parameters:
# -------------------------------------------------------------------------
# None.
#
# Change History:
#
# Date          Name            Comments
# _________________________________________________________________________
# 5 Mar 2003    purdym          new

# Verify command line arguments
if [[ $# -lt 1 ]]
then
 echo
 echo "Usage: $0 directory [archive_management_class]"
 echo
 exit -1
fi

# command line args
DIRECTORY=$1
MC=$2
ARCHMC=${MC:=forever}                                   # put your default 
archiving MC here

WORK_DIR=${WORK_DIR:=/tmp}
COLUMNS=`stty -a 2>/dev/null | grep columns | cut -d" " -f6`

UNIX_SYSTEM_DIRECTORY=${UNIX_SYSTEM_DIRECTORY:=/home/unxsa}
SCRDIR=$UNIX_SYSTEM_DIRECTORY/bin

SEP="=========================================================================================================="
SEP1="---------------------------------------------------------------------------------------------------------"
RETCODE=0
RETCODE1=0
RETCODE1=$?; if [[ $RETCODE -eq 0 ]]; then RETCODE=$RETCODE1; fi

OUT_FILE=$DIRECTORY/run_me_to_restore_this_directory_from_tsm.$$
DATE=`date +%d%b%Y_%H:%M:%S`
###################################################################################
#
###################################################################################
echo "\n\n$0 started at $(date)."
echo $SEP1 | cut -c -${COLUMNS}

if [[ $DIRECTORY = '/' || $DIRECTORY = '/usr' || $DIRECTORY = '/etc' || 
$DIRECTORY = '/var' || $DIRECTORY = '/home' ]]
then
  echo "Can't use $DIRECTORY."
  exit -1
fi

if [[ `whoami` != "root" ]]
then
  echo "Error: this script can only be run by root."
  exit -1
fi

if [[ -f $OUT_FILE ]]
then
  exit -1
fi

# first let's archive it
echo running dsmc arch -archmc=$ARCHMC -desc="$DIRECTORY $DATE" ${DIRECTORY}/
dsmc arch -archmc=$ARCHMC -desc="$DIRECTORY $DATE" ${DIRECTORY}/
RETCODE1=$?; if [[ $RETCODE -eq 0 ]]; then RETCODE=$RETCODE1; fi
if [[ $RETCODE1 -ne 0 ]]
then
  exit -1
fi

echo running rm -r ${DIRECTORY}/
rm -r ${DIRECTORY}/*
RETCODE1=$?; if [[ $RETCODE -eq 0 ]]; then RETCODE=$RETCODE1; fi

echo dsmc retrieve -desc=\"$DIRECTORY $DATE\" ${DIRECTORY}/             
>$OUT_FILE
chmod 700 $OUT_FILE
RETCODE1=$?; if [[ $RETCODE -eq 0 ]]; then RETCODE=$RETCODE1; fi

###################################################################################
#
###################################################################################
echo "\n\n$0 Ended at $(date)"
echo $SEP1 | cut -c -${COLUMNS}

exit $RETCODE


----------------------------------------------------------------------------------------------
Miles Purdy
System Manager
Information Systems Team (IST),
Farm Income Programs Directorate (FIPD),
Agriculture and Agri-Food Canada (AAFC)
Winnipeg, MB, CA
purdym AT fipd.gc DOT ca
ph: (204) 984-1602 fax: (204) 983-7557

"If you hold a UNIX shell up to your ear, can you hear the C?"
-------------------------------------------------------------------------------------------------




--

I don't suffer from Insanity...         | Linux User #16396
       I enjoy every minute of it...   |
                                       |
http://www.travellingkiwi.com/          |

<Prev in Thread] Current Thread [Next in Thread>