TSM Cirkuláris Másolatkészítő szkript

A primary pool-okat, amiket a PRIM_POOL_WHERE változóban megadott SQL feltétellel definiálunk, folyamatosan másolja az azonos nevű, _C végű copy poolokba. Egy időben BACKUPMAXNUM „backup stg” processzt enged futni, amit REFRESHRATE percenként vizsgál. Az INFINITERUN=true esetén ha a storage pool lista végére ért, kezdi előről.

tsm_circular_ba_stg.sh
#!/bin/sh
#                                                               	#
# TSM Circular Backup Storage Pool v1.0 (2016.11.16) - Ágoston Péter	#
#                                                               	#
#########################################################################
TSMSERVER=tsmserv
TSMUSER=tsmadmin
TSMPASS=jelszo
BACKUPMAXNUM=4
INFINITERUN=true
REFRESHRATE=30 #MINUTES
PRIM_POOL_WHERE="stgpool_name like '%_T' and stgpool_name like '%_D'"
LOGFILE=/var/log/tsm_circular_ba_stg.log
LOGMAXLINES=3000
REMEMBER_LAST_POOL=true
LAST_POOL_FILE=/tmp/tsm_circular_ba_stg.last_pool
EXCLUDEPOOLS=''
 
DSMADMC="dsmadmc -id=$TSMUSER -pa=$TSMPASS -se=$TSMSERVER -dataonly=y -displ=tabl"
 
if [[ $(ps -ef | grep $0 | grep -vc grep) -gt 1 ]]; then
        echo "$(date "+%Y.%m.%d %H:%M") A PROGRAM MAR FUT EGY PELDANYBAN!" | tee -a $LOGFILE
        exit 1
fi
 
trap 'echo "$(date "+%Y.%m.%d %H:%M") PROGRAM TERMINATED" | tee -a $LOGFILE;kill $$' SIGINT SIGTERM;
 
echo "$(date "+%Y.%m.%d %H:%M") PROGRAM START (TSMSERVER=$TSMSERVER, BACKUPMAXNUM=$BACKUPMAXNUM, INFINITERUN=$INFINITERUN, REFRESHRATE=${REFRESHRATE}m)" | tee -a $LOGFILE
LAST_POOL=$(cat $LAST_POOL_FILE)
FIRSTRUN=true
CYCLE=1
while [ $INFINITERUN = true ] || [ $FIRSTRUN = true ]; do
    tail -n$LOGMAXLINES $LOGFILE > $LOGFILE.trunc && mv $LOGFILE.trunc $LOGFILE
    ACT_POOL_NUM=1
    FIRSTRUN=false
    STARTTIME=$(date +"%s")
    STARTTIME=$(($STARTTIME / 60))
    echo "$(date "+%Y.%m.%d %H:%M") CYCLE START ($CYCLE)" | tee -a $LOGFILE
    PRIMARY_POOL_NUM=`$DSMADMC "select count(*) from stgpools where ${PRIM_POOL_WHERE} and POOLTYPE='PRIMARY'" | sed 's/[^0-9]*//'`
	$DSMADMC "select stgpool_name from stgpools where ${PRIM_POOL_WHERE} and POOLTYPE='PRIMARY' ORDER BY stgpool_name" | while read POOL; do
        # Megprobaljuk onnan folytatni, ahol utoljara abbahagytuk a kort
        if [ "$REMEMBER_LAST_POOL" = "true" ] && [ -n "$LAST_POOL" ] && [ "$POOL" != "$LAST_POOL" ]; then 
            echo "$(date "+%Y.%m.%d %H:%M") #$CYCLE A $POOL node kihagyasa, mert folytatjuk onnan, ahol abbahagytuk." | tee -a $LOGFILE
            ACT_POOL_NUM=$((ACT_POOL_NUM+1))
            continue; 
        fi
        unset LAST_POOL
        # Ha nem fut meg a pool-ra mosolatkeszites, elinditjuk ra
        if [ $($DSMADMC "select count(*) from processes where status like '% $POOL,%' and process='Backup Storage Pool'") -eq 0 ] && [ "$(echo $EXCLUDEPOOLS | grep -c $POOL)" -eq 0 ]; then
            BACKUPNUM=$($DSMADMC "select count(*) from processes where process='Backup Storage Pool'" | sed 's/[^0-9]//g')
            ACTPOOLS=$($DSMADMC "select status from processes where process='Backup Storage Pool'" | grep -v 'AN[SR]' | sed -e 's/\(^.*Primary Pool \)\([^,]*\)\(.*$\)/\2/' | tr '\n' ',')
            echo ${ACTPOOLS%%,*} > $LAST_POOL_FILE
	        echo "$(date "+%Y.%m.%d %H:%M") #$CYCLE Futo masolatkeszitesek szama: $BACKUPNUM ($ACT_POOL_NUM/$PRIMARY_POOL_NUM) | Varakozik: $POOL | Masolatkeszites alatt: $ACTPOOLS" | tee -a $LOGFILE
            # Varunk, amig lesz masolatkeszito "slot"
            while [ $BACKUPNUM -ge $BACKUPMAXNUM ]; do
                echo "$(date "+%Y.%m.%d %H:%M") #$CYCLE ${REFRESHRATE}p varakozas..." | tee -a $LOGFILE
                sleep $(($REFRESHRATE*60))
				BACKUPNUM=$($DSMADMC "select count(*) from processes where process='Backup Storage Pool'" | sed 's/[^0-9]//g')
				ACTPOOLS=$($DSMADMC "select status from processes where process='Backup Storage Pool'" | grep -v 'AN[SR]' | sed -e 's/\(^.*Primary Pool \)\([^,]*\)\(.*$\)/\2/' | tr '\n' ',')
	            echo "$(date "+%Y.%m.%d %H:%M") #$CYCLE Futo masolatkeszitesek szama: $BACKUPNUM ($ACT_POOL_NUM/$PRIMARY_POOL_NUM) | Varakozik: $POOL | Masolatkeszites alatt: $ACTPOOLS" | tee -a $LOGFILE
            done
 
            COPYPOOL="${POOL%_[DT]}_C"
            if [[ $($DSMADMC "select count(*) from stgpools where stgpool_name='$COPYPOOL'" | sed 's/[^0-9]//g') -eq 0 ]]; then
                echo "$(date "+%Y.%m.%d %H:%M") #${CYCLE} A $POOL-hoz nem letezik $COPYPOOL masolati pool, ezert kihagyjuk" | tee -a $LOGFILE
            else
                $DSMADMC "BACKUP STG $POOL $COPYPOOL " | tee -a $LOGFILE
            fi
            ACT_POOL_NUM=$((ACT_POOL_NUM+1))
            # Ha mar csak egy slot van, varunk egy percet, hatha nincs mit masolni, hogy mehessunk tovabb
            if [ $(($BACKUPMAXNUM-$BACKUPNUM)) -eq 1 ]; then echo "$(date "+%Y.%m.%d %H:%M") #$CYCLE 1p varakozas..." | tee -a $LOGFILE;sleep 60; fi
        else
            echo "$(date "+%Y.%m.%d %H:%M") #$CYCLE A $POOL kihagyasra kerul, mert EXCLUDE-olva van, vagy mar epp fut ra masolatkeszites." | tee -a $LOGFILE
        fi
	done
    ENDTIME=$(date +"%s")
    ENDTIME=$(($ENDTIME / 60))
    RUNTIME=$(($ENDTIME-$STARTTIME))
    echo "$(date "+%Y.%m.%d %H:%M") CYCLE END ($CYCLE) | RUNTIME: $(($RUNTIME / 60))h $(($RUNTIME % 60))m" | tee -a $LOGFILE
    echo | tee -a $LOGFILE
    echo "$(date "+%Y.%m.%d %H:%M") ${REFRESHRATE}p varakozas..." | tee -a $LOGFILE
    sleep $(($REFRESHRATE*60))
    CYCLE=$(($CYCLE + 1))
    unset LAST_POOL
done
echo "$(date "+%Y.%m.%d %H:%M") PROGRAM END" | tee -a $LOGFILE
shell/circular_copy.txt · Utolsó módosítás: 2016/11/16 16:27 szerkesztette: admin
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0