Table of Contents

Clone Data Script

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.

Environment Variables

Script Explanation

1. Logging Setup

touch $LOGFILE
exec 2>&1
exec >> $LOGFILE

2. Date Variable

DATE="date +\%Y-\%m-\%d\ \%H:\%M:\%S"

3. Start Log Entry

echo "["$(eval $DATE)"] Clone backup start"

4. Checking Remote Backups Availability

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

5. Synchronizing Backup

rsync -ahvz -H --delete --exclude='out.log' --exclude=".*" --exclude='anonymization' -e 'ssh -p 2224' $BACKUPS_HOST:/upload/ $BACKUP_DIR

6. Cleanup

rm $BACKUP_DIR/output.log

7. Completion Log Entry

echo "["$(eval $DATE)"] Done"

Nadir Habib 2024/06/05 14:53