Basic Rsync Script For Transferring Or Synchronizing Files From One Server (Sourcesrv) To Another Server (Destinationsrv)
Basic Rsync Script For Transferring Or Synchronizing Files From One Server (SourceSrv) To Another Server (DestinationSrv)
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:/data/docs/
export Destination=/data/docs/
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
############################################################
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