This script automates the process of backing up files from a remote server to a local directory. It uses rsync over SSH to ensure that the local backup directory is synchronized with the remote directory. The script includes logging capabilities and retry mechanisms in case of connection issues.
touch $LOGFILE exec 2>&1 exec >> $LOGFILE
DATE="date +\%Y-\%m-\%d\ \%H:\%M:\%S"
echo "["$(eval $DATE)"] Clone backup start"
while ! ssh -p 2224 $BACKUPS_HOST stat /upload/*.* \> /dev/null ; do echo "["$(eval $DATE)"] Cannot contact backup server. Retrying in 1mn" sleep 30 done sleep 2
rsync -ahvz -H --delete --exclude='out.log' --exclude=".*" --exclude='anonymization' -e 'ssh -p 2224' $BACKUPS_HOST:/upload/ $BACKUP_DIR
rm $BACKUP_DIR/output.log
echo "["$(eval $DATE)"] Done"
— Nadir Habib 2024/06/05 14:53