Bash Script For Transferring Or Synchronizing RMAN Backup Files From One Server (SourceSrv) To Another Server (DestinationSrv) And Deleting Old RMAN Backup Files
Bash Script For Transferring Or Synchronizing RMAN Backup Files From One Server (SourceSrv) To Another Server (DestinationSrv) And Deleting Old RMAN Backup Files
Source Host: SourceSrv Destination Host: DestinationSrv
LogIn on DestinationSrv:
mkdir -p /home/rony/.scripts/
touch /home/rony/.scripts/rsync.sh
touch /home/rony/.scripts/rsync.log
chmod u+x /home/rony/.scripts/rsync.sh
For killall command install: sudo dnf search psmisc
tee /home/rony/.scripts/rsync.sh >/dev/null <<EOF
#!/bin/bash
##################################################################################################################
export Script=/home/rony/.scripts/
export Source=rony@SourceSrv:/u01/rman_backup/
export Destination=/u01/db_backup/backup_from_DestinationSrv/rman/backup_files/
export LogFile=${Script}/rsync.log
echo 'Source : '${Source} 2>&1 | tee -a ${Script}/rsync.log
echo 'Destination : '${Destination} 2>&1 | tee -a ${Script}/rsync.log
##################################################################################################################
echo 'Task-01: Kill already running rsync process. Start at '$(date) 2>&1 | tee -a ${Script}/rsync.log
sleep 30
killall rsync
sleep 30
echo 'Task-01: Kill already running rsync process. End at '$(date) 2>&1 | tee -a ${Script}/rsync.log
##################################################################################################################
echo 'Task-02: Transfering RMAN Backup Files From '${Source}' to '${Destination}'.. Start at '$(date) 2>&1 | tee -a ${Script}/rsync.log
sleep 30
rsync --log-file=${LogFile} -avrPh --force -e ssh ${Source} ${Destination}
sleep 30
echo 'Task-02: Transfering RMAN Backup Files From '${Source}' to '${Destination}'.. End at '$(date) 2>&1 | tee -a ${Script}/rsync.log
##################################################################################################################
echo 'Task-03: Deleting 10 Days Older Files.. Start at '$(date) 2>&1 | tee -a ${Script}/rsync.log
echo 'Print all dir------------------------------------------------Start' 2>&1 | tee -a ${Script}/rsync.log
for dir in ${Destination[@]}
do
echo 'Backup_Diretory: '$dir 2>&1 | tee -a ${Script}/rsync.log
for readDir in $dir
do
echo 'Reading_Directory: ' $readDir 2>&1 | tee -a $Script/rsync.log cd $readDir #ls echo 'pwd: ' $(pwd) 2>&1 | tee -a $Script/rsync.log
echo 'Print ten days older all files------------------------------------------------Start' 2>&1 | tee -a ${Script}/rsync.log
for file in $(find $readDir -mtime +7)
do
echo 'File_name : '$file 2>&1 | tee -a ${Script}/rsync.log
echo '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
echo 'delete start for the file: '$file 2>&1 | tee -a ${Script}/rsync.log
echo 'Please wait................' 2>&1 | tee -a ${Script}/rsync.log
rm -rfv $file
echo 'delete completed for the file: '$file 2>&1 | tee -a ${Script}/rsync.log
echo '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
done
echo 'Print ten days older all files------------------------------------------------End' 2>&1 | tee -a ${Script}/rsync.log
done
done
echo 'Print all dir------------------------------------------------End' 2>&1 | tee -a ${Script}/rsync.log
echo 'Task-03: Deleting 10 Days Older Files.. End at '$(date) 2>&1 | tee -a ${Script}/rsync.log
##################################################################################################################
EOF
crontab -e
#11 18 * * * /home/rony/.scripts/rsync.sh
watch -n 1 'tail -n 29 /var/log/cron'
watch -n 1 'ps -axuwwf | grep rsync'
watch -n 1 'tail -n 29 /home/rony/.scripts/rsync.log'
Comments
Post a Comment