Scripts to archive the File:
#
******************************************************************************
# Script
Name : arch_files_XXXX.ksh
# Author : XXXX Datastage Team (OHRD)
# Creation Date
: 15-Dec-08
# Version :
#
Description : Script is for the taking the backup of files
and after taking backup of the file
# removing 15 days older
file.
#
#
# This script uses parameters
from a given 'unified' parameter file
# (ie. all parameters for running the job
in datastage from the file)
# $1 - Parameter file path
# $2 - Unified Parameter file
name
#
******************************************************************************
# Change
History:
# Date:
15-Dec-2008 XXXX Datastage
Team Description: New script
#
******************************************************************************
##############################################################################################
# Name:
print_formatted_date
# Desc: prints
the formatted date to the log file
##############################################################################################
print_formatted_date
() {
local print_file=$*
set `date -u +"%a %d %h %Y
%T"` # date in
format Wed 29 May 2002 09:17:46
local dayw=$1
local dayd=$2
local month=$3
local year=$4
local time=$5
local pid=$$
printf "%-3s %2s %-3s %-4s %-8s GMT %-6s
" ${dayw} ${dayd} ${month} ${year} ${time}
"${pid}:" >> $print_file
}
##############################################################################################
# Name:
write_log
# Desc: write
message to log prefixed by current date and time
# Args: $1 ->
The message to be output
##############################################################################################
function
write_log {
print_formatted_date $script_log
print $* >> $script_log
} # write_log
##############################################################################################
# Name:
exit_script
# Desc: write
relevant message to log - exit script
with passed exit code
# Args: exit
code
##############################################################################################
function
exit_script {
if [[ $1 -eq 0 ]]
then
out_msg="Script
arch_files_XXXX.ksh - ended successfully"
else
out_msg="Script
arch_files_XXXX.ksh - ended abnormally"
fi
write_log "$out_msg"
exit $1
} # exit_script
############################ MAIN
##################################################
#
**************************
# SCRIPT STARTED
#
**************************
#set -x
cd $1
cat $2 | tr -ds
"$" "" > arch_files_XXXX.param_3
export `cat
arch_files_XXXX.param_3`
chmod 777 arch_files_XXXX.param_3
script_log=$prmDirJobLog/arch_files_XXXX.log
rm -f
$script_log
write_log
"Script arch_files_XXXX.ksh Started..."
datetime=`date
+%Y%m%d`
mkdir
$prmDirArchive/XXXX_${datetime}
mkdir
$prmDirArchive/XXXX_${datetime}/landing
mkdir
$prmDirArchive/XXXX_${datetime}/targets
mkdir
$prmDirArchive/XXXX_${datetime}/joblogs
mkdir
$prmDirArchive/XXXX_${datetime}/prm
mkdir
$prmDirArchive/XXXX_${datetime}/scripts
mkdir
$prmDirArchive/XXXX_${datetime}/restore
mkdir
$prmDirArchive/XXXX_${datetime}/staging
mkdir
$prmDirArchive/XXXX_${datetime}/intermediate
mkdir
$prmDirArchive/XXXX_${datetime}/reject
for i in as tc
wl
do
for j in ape
do
if [ -f $prmDirLanding/XXXX_${j}_${i}_snd.dat
]
then
write_log "Archived XXXX_${j}_${i}_snd.dat
file..."
mv $prmDirLanding/XXXX_${j}_${i}_snd.dat
$prmDirArchive/XXXX_${datetime}/landing/
fi
if [ -f $prmDirLanding/XXXX_${j}_${i}_snd_orig.dat
]
then
write_log "Archived XXXX_${j}_${i}_snd_orig.dat
file..."
mv $prmDirLanding/XXXX_${j}_${i}_snd_orig.dat
$prmDirArchive/XXXX_${datetime}/landing/
fi
if [ -f $prmDirLanding/XXXX_${j}_${i}_snd_header.dat
]
then
write_log "Archived XXXX_${j}_${i}_snd_header.dat
file..."
mv $prmDirLanding/XXXX_${j}_${i}_snd_header.dat
$prmDirArchive/XXXX_${datetime}/landing/
fi
if [ -f $prmDirIntermediate/XXXX_${j}_${i}_inter.dat
]
then
write_log "Archived XXXX_${j}_${i}_inter.dat
file..."
mv $prmDirIntermediate/XXXX_${j}_${i}_inter.dat
$prmDirArchive/XXXX_${datetime}/intermediate/
fi
if [ -f $prmDirTargets/${j}_${i}_etl_sem_XXXX.dat
]
then
write_log "Archived
${j}_${i}_etl_sem_XXXX.dat file..."
mv
$prmDirTargets/${j}_${i}_etl_sem_XXXX.dat $prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f $prmDirTargets/${j}_${i}_etl_event_queue_XXXX.dat
]
then
write_log "Archived
${j}_${i}_etl_event_queue_XXXX.dat file..."
mv
$prmDirTargets/${j}_${i}_etl_event_queue_XXXX.dat $prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f
$prmDirTargets/${j}_${i}_comm_hist.dat ]
then
write_log "Archived
${j}_${i}_comm_hist.dat file..."
mv
$prmDirTargets/${j}_${i}_comm_hist.dat $prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f $prmDirTargets/${j}_${i}_etl_event_queue_detail_XXXX.dat ]
then
write_log "Archived
${j}_${i}_etl_event_queue_detail_XXXX.dat file..."
mv
$prmDirTargets/${j}_${i}_etl_event_queue_detail_XXXX.dat $prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f
$prmDirTargets/${j}_${i}_etl_customer_master_XXXX.dat ]
then
write_log "Archived
${j}_${i}_etl_customer_master_XXXX.dat file..."
mv $prmDirTargets/${j}_${i}_etl_customer_master_XXXX.dat
$prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f
$prmDirTargets/${j}_${i}_etl_cust_subscription_XXXX.dat ]
then
write_log "Archived
${j}_${i}_etl_cust_subscription_XXXX.dat file..."
mv
$prmDirTargets/${j}_${i}_etl_cust_subscription_XXXX.dat $prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f $prmDirTargets/XXXX_${j}_${i}_rspnd.dat
]
then
write_log "Archived XXXX_${j}_${i}_rspnd.dat
file..."
mv $prmDirTargets/XXXX_${j}_${i}_rspnd.dat
$prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f
$prmDirTargets/${j}_${i}_rspnd.dat ]
then
write_log "Archived
${j}_${i}_rspnd.dat file..."
mv
$prmDirTargets/${j}_${i}_rspnd.dat $prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f
$prmDirIntermediate/${j}_${i}_dialogue_inter.xml ]
then
write_log "Archived
${j}_${i}_dialogue_inter.xml file in intermediate..."
mv
$prmDirIntermediate/${j}_${i}_dialogue_inter.xml $prmDirArchive/XXXX_${datetime}/intermediate/
fi
if [ -f
$prmDirTargets/${j}_${i}_dialogue_inter.xml ]
then
write_log "Archived
${j}_${i}_dialogue_inter.xml file in targets..."
mv
$prmDirTargets/${j}_${i}_dialogue_inter.xml $prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f
$prmDirIntermediate/${j}_${i}_etl_event_queue_XXXX.dat ]
then
write_log "Archived
${j}_${i}_etl_event_queue_XXXX.dat file..."
mv
$prmDirIntermediate/${j}_${i}_etl_event_queue_XXXX.dat $prmDirArchive/XXXX_${datetime}/intermediate/
fi
if [ -f $prmDirTargets/${j}_${i}_dialogue.xml*
]
then
write_log "Archived
${j}_${i}_dialogue.xml* file..."
mv
$prmDirTargets/${j}_${i}_dialogue.xml* $prmDirArchive/XXXX_${datetime}/targets/
fi
done
if [ -f $prmDirIntermediate/XXXX_send_${i}_inter.dat
]
then
write_log "Archived XXXX_send_${i}_inter.dat..."
mv $prmDirIntermediate/XXXX_send_${i}_inter.dat
$prmDirArchive/XXXX_${datetime}/intermediate/
fi
if [ -f
$prmDirIntermediate/snd_${i}_dialogue_inter.xml ]
then
write_log "Archived
snd_${i}_dialogue_inter.xml file in intermediate..."
mv
$prmDirIntermediate/snd_${i}_dialogue_inter.xml $prmDirArchive/XXXX_${datetime}/intermediate/
fi
if [ -f
$prmDirTargets/snd_${i}_dialogue_inter.xml ]
then
write_log "Archived
snd_${i}_dialogue_inter.xml file in targets..."
mv
$prmDirTargets/snd_${i}_dialogue_inter.xml $prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f
$prmDirTargets/snd_${i}_dialogue.xml* ]
then
write_log "Archived
snd_${i}_dialogue.xml* file..."
mv
$prmDirTargets/snd_${i}_dialogue.xml* $prmDirArchive/XXXX_${datetime}/targets/
fi
done
if [ -f
$prmDirTargets/XXXX_dlg_snd*.xml ]
then
write_log "Archived XXXX_dlg_snd*.xml
file..."
mv $prmDirTargets/XXXX_dlg_snd*.xml
$prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f
$prmDirTargets/CBI-XXXX_COMMS_DATA.* ]
then
write_log "Archived CBI-XXXX_COMMS_DATA.*
file..."
mv $prmDirTargets/CBI-XXXX_COMMS_DATA.*
$prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f
$prmDirLanding/XXXX_*_cha.dat ]
then
write_log "Archived XXXX_*_cha.dat
file..."
mv $prmDirLanding/XXXX_*_cha.dat
$prmDirArchive/XXXX_${datetime}/landing/
fi
if [ -f
$prmDirLanding/XXXX_*_chs.dat ]
then
write_log "Archived XXXX_*_chs.dat
file..."
mv $prmDirLanding/XXXX_*_chs.dat
$prmDirArchive/XXXX_${datetime}/landing/
fi
if [ -f
$prmDirLanding/XXXX_ape_pros_cust_upd*.dat ]
then
write_log "Archived XXXX_ape_pros_cust_upd.dat
file..."
mv $prmDirLanding/XXXX_ape_pros_cust_upd*.dat
$prmDirArchive/XXXX_${datetime}/landing/
fi
if [ -f
$prmDirTargets/pros_cust_upd*.dat ]
then
write_log "Archived
pros_cust_upd*.dat file..."
mv
$prmDirTargets/pros_cust_upd*.dat $prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f
$prmDirTargets/XXXX_pros_cust_upd*.dat ]
then
write_log "Archived XXXX_pros_cust_upd*.dat
file..."
mv $prmDirTargets/XXXX_pros_cust_upd*.dat
$prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f
$prmDirTargets/XXXX_ondmnd_resnd.dat ]
then
write_log "Archived XXXX_ondmnd_resnd.dat
file..."
mv $prmDirTargets/XXXX_ondmnd_resnd.dat
$prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f
$prmDirTargets/ondemand_*.dat ]
then
write_log "Archived
ondemand_*.dat file..."
mv
$prmDirTargets/ondemand_*.dat $prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f
$prmDirTargets/Snd_ReSnd_Xtract_log*.dat ]
then
write_log "Archived
Snd_ReSnd_Xtract_log*.dat file..."
mv
$prmDirTargets/Snd_ReSnd_Xtract_log*.dat $prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f
$prmDirTargets/XXXX_error_report_ext.dat ]
then
write_log "Archived
ccm_error_report_ext.dat file..."
mv $prmDirTargets/XXXX_error_report_ext.dat
$prmDirArchive/XXXX_${datetime}/targets/
fi
if [ -f $prmDirRejects/*.bad
]
then
write_log "Archived all
reject files..."
mv $prmDirRejects/*.bad
$prmDirArchive/XXXX_${datetime}/reject/
fi
find
$prmDirArchive/XXXX_* -type f -mtime + $prmFileArchDays -exec ls -lt {} \; >> $script_log
find
$prmDirArchive -type d -name "XXXX_*" -mtime +$prmFileArchDays -exec
rm -r {} \;
cd $1
files=`ls
arch_files_XXXX.param_3`
write_log
"Deleting temporary file: $files."
rm -f $files
exit_script 0
No comments:
Post a Comment