Pages

Monday, September 16, 2024

scp backup files to backup mng server

General
On oracle server
RMAN script running at 03:00
expdp script running at 02:00
scp scripts running at 05:00 and 05:30

On backup server
Clean old backups script running at 01:00

scripts on oracle server

00 02 * * * /etc/sh/backup/export_all_instances.sh
00 03 * * * /etc/sh/backup/jobs/run_rman_backup_cron.sh igt
00 05 * * * /home/user/scripts/send_to_mng.sh
30 05 * * * /home/user/scripts/send_to_mng_exp.sh

/home/user/scripts/send_to_mng.sh
#!/bin/bash

RUN_DATE=`date +"%Y%m%d"`

DIR_PREFIX=$RUN_DATE

REMOTE_USER=user
REMOTE_SERVER=mng_server-01
REMOTE_PATH=/backup/ipn_backup/ora_online

LOCAL_DIR=/backup/ora_online/for_backup
KEEP_DAYS=10

is_active_server=`ps -ef | grep ora_pmon_igt | grep -v grep | wc -l`
if [[ $is_active_server -eq 0 ]]; then
 echo "Oracle is not running on this server" 
 exit 0
fi

cd ${LOCAL_DIR}
last_backup_dir=`ls -ltr | grep ${DIR_PREFIX} | tail -1 | awk '{print $9}'`

if [[ -d $last_backup_dir ]]; then
 echo "tar -cvf ${last_backup_dir}.tar ${last_backup_dir}"
 tar -cvf ${last_backup_dir}.tar ${last_backup_dir}
 echo "scp -p  ${LOCAL_DIR}/${last_backup_dir}.tar ${REMOTE_USER}@${REMOTE_SERVER}:${REMOTE_PATH}/${last_backup_dir}.tar"
 scp -p  ${LOCAL_DIR}/${last_backup_dir}.tar ${REMOTE_USER}@${REMOTE_SERVER}:${REMOTE_PATH}/${last_backup_dir}.tar
 rm -f ${LOCAL_DIR}/${last_backup_dir}.tar
else
 echo "No Archive Directory to Send to mng"
fi

/home/user/scripts/send_to_mng_exp.sh
#!/bin/bash

RUN_DATE=`date +"%Y%m%d"`
FILE_PREFIX=export_igt
FILE_SUFFIX=dmp
FILE_SUFFIX_LOG=log
REMOTE_USER=user
REMOTE_SERVER=mng_server-01
REMOTE_PATH=/backup/ipn_backup/exp_backup
LOCAL_DIR=/backup/ora_exp/for_backup
LOCAL_LOG_DIR=/backup/ora_exp/for_backup/old_log

cd ${LOCAL_DIR}
last_backup_file=`ls -ltr | grep ${FILE_PREFIX} | grep ${FILE_SUFFIX} | tail -1 | awk '{print $9}'`

if [[ -f $last_backup_file ]]; then 
 #echo "scp ${REMOTE_USER}@${REMOTE_SERVER}:${REMOTE_PATH}/${last_backup_file} ${LOCAL_DIR}/${last_backup_file}"
 scp ${LOCAL_DIR}/${last_backup_file} ${REMOTE_USER}@${REMOTE_SERVER}:${REMOTE_PATH}/${last_backup_file} 
else
 echo "No export dmp file to send to mng"
fi
log_files=`ls -1 ${LOCAL_DIR}/${FILE_PREFIX}*${FILE_SUFFIX_LOG} 2>/dev/null | wc -l`
if [[ $log_files -gt 0 ]]; then
 mv -f ${LOCAL_DIR}/${FILE_PREFIX}*${FILE_SUFFIX_LOG} ${LOCAL_LOG_DIR}
fi

KEEP_BACKUPS=1
cd ${LOCAL_DIR}
#echo "expdp dmp files: ls -1 ${FILE_PREFIX}*${FILE_SUFFIX} | wc -l"
backups_number=`ls -1 ${FILE_PREFIX}*${FILE_SUFFIX} | wc -l`
#echo "backups_number = $backups_number"
while [[ $backups_number -gt $KEEP_BACKUPS ]]; do
 backup_name=`ls -ltr ${FILE_PREFIX}*${FILE_SUFFIX} | head -1 | awk '{print $9}'`
 #echo "rm -f $backup_name"
 rm -f $backup_name
 backups_number=`ls -1 ${FILE_PREFIX}*${FILE_SUFFIX} | wc -l`
done

scripts on mng server
00 01 * * * /home/user/scripts/del_old_backups.sh

/home/user/scripts/del_old_backups.sh
#!/bin/bash

LOCAL_DIR=/backup/ipn_backup/ora_online
RUN_DATE=`date +"%Y%m%d"`

BACKUP_SUFFIX=tar
KEEP_BACKUPS=4

cd ${LOCAL_DIR}
backups_number=`ls -1 *${BACKUP_SUFFIX} | wc -l`
while [[ $backups_number -gt $KEEP_BACKUPS ]]; do
 backup_name=`ls -ltr | grep ${BACKUP_SUFFIX} | head -1 | awk '{print $9}'`
 rm -f $backup_name
 backups_number=`ls -1 *${BACKUP_SUFFIX} | wc -l`
done

LOCAL_DIR=/backup/ipn_backup/exp_backup
FILE_PREFIX=export_igt
BACKUP_SUFFIX=dmp
KEEP_BACKUPS=2

cd ${LOCAL_DIR}
backups_number=`ls -1 ${FILE_PREFIX}*${BACKUP_SUFFIX} | wc -l`
while [[ $backups_number -gt $KEEP_BACKUPS ]]; do
 backup_name=`ls -ltr | grep ${FILE_PREFIX} | grep ${BACKUP_SUFFIX} | head -1 | awk '{print $9}'`
 rm -f $backup_name
 backups_number=`ls -1 ${FILE_PREFIX}*${BACKUP_SUFFIX} | wc -l`
done

No comments:

Post a Comment