From 4c790f64daf7822de00405140d17e08f296a642f Mon Sep 17 00:00:00 2001 From: Steve Smokowski Date: Thu, 9 Feb 2017 15:27:43 -0500 Subject: Initial OpenECOMP A&AI commit Change-Id: I8b06519995d9dc0f220b80a6d9a71865b23e4edb Signed-off-by: Steve Smokowski --- ajsc-aai/src/main/scripts/dotOutEnd_cleanup.sh | 81 ++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 ajsc-aai/src/main/scripts/dotOutEnd_cleanup.sh (limited to 'ajsc-aai/src/main/scripts/dotOutEnd_cleanup.sh') diff --git a/ajsc-aai/src/main/scripts/dotOutEnd_cleanup.sh b/ajsc-aai/src/main/scripts/dotOutEnd_cleanup.sh new file mode 100644 index 0000000..79ca663 --- /dev/null +++ b/ajsc-aai/src/main/scripts/dotOutEnd_cleanup.sh @@ -0,0 +1,81 @@ +#!/bin/ksh +# +# ============LICENSE_START======================================================= +# org.openecomp.aai +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# ============LICENSE_END========================================================= +# +# This script uses the dataSnapshot and SchemaGenerator (via GenTester) java classes to restore +# data to a database by doing three things: +# 1) clear out whatever data and schema are currently in the db +# 2) rebuild the schema (using the SchemaGenerator) +# 3) reload data from the passed-in datafile (which must found in the dataSnapShots directory and +# contain an xml view of the db data). +# +# +# The script archives/deletes files that end in .out (Ie. dataGrooming.201511111305.out) that sit in our log/data directory structure +# + +userid=$( id | cut -f2 -d"(" | cut -f1 -d")" ) +if [ "${userid}" != "aaiadmin" ]; then + echo "You must be aaiadmin to run $0. The id used $userid." + exit 1 +fi + +. /etc/profile.d/aai.sh +PROGNAME=$(basename $0) +LOGDIR=${PROJECT_HOME}/logs +ZIPDIR=ARCHIVE +AGEZIP=30 +AGEDELETE=60 +ZIPPER=/bin/gzip +DATE=$(date +%Y%m%d) + +# Get the program arguments +if [[ $# -lt 3 ]] +then + echo "${PROGNAME}: Arguments are missing. Found $#" + exit 1 +fi +LOGDIR="${1}" +AGEZIP=$2 +AGEDELETE=$3 +if [[ ! -d $LOGDIR ]] +then + echo "${PROGNAME}: Directory does not exist: ${LOGDIR}" + exit 1 +fi + +# Create the archive folder, if it does not exist. +if [[ ! -d ${LOGDIR}/${ZIPDIR} ]] +then + mkdir ${LOGDIR}/${ZIPDIR} + if [ $? -ne 0 ] + then + echo "${PROGNAME}: Failed to create directory: ${LOGDIR}/${ZIPDIR}" + exit 1 + fi + chmod 777 ${LOGDIR}/${ZIPDIR} +fi + +# Compress files that are older than AGEZIP days +find -L ${LOGDIR} -name *.gz -prune -o -mtime +${AGEZIP} -type f -name "*.out" -exec ${ZIPPER} -f {} \; +find -L ${LOGDIR} -name ${ZIPDIR} -prune -o -type f -name "*.out.gz" -print | while read i; do dirnm=`dirname ${i}`; drn=`basename ${dirnm}`; mkdir -p ${LOGDIR}/${ZIPDIR}/${drn}; echo ${i}; echo ${LOGDIR}/${ZIPDIR}/${drn}; mv ${i} ${LOGDIR}/${ZIPDIR}/${drn}; done + +# Delete archive files that are older than AGEDELETE days +find -L ${LOGDIR}/${ZIPDIR}/* -type f -name "*.gz" -mtime +${AGEDELETE} -exec rm -r {} \; + +exit 0 -- cgit 1.2.3-korg