Script to Copy Yesterdays DB Backup to Remote Site

The following script will pick out yesterdays backup file and copy it over to a remote site using SCP

Note: The format of the backup files are in this format : db-08-10-2019.bak.gz

Note: You will need to install sshpass (eg yum -y install sshpass) and be comfortable with your password being in cleartext.

#!/usr/bin/bash
# TARGET HOST (REMOTE)
TARGET=remotebackups.jordansphere.co.uk
USER=backupuser
PASSWORD=password
LOCALDIR=/DB-BACKUPS
REMOTEDIR=/BACKUPS/DB-BACKUPS
#Yesterdays date
YESTERDAY=$(date -d yesterday "+%d-%m-%Y")


sshpass -p $PASSWORD scp $LOCALDIR/db-$YESTERDAY.bak.gz backupuser@$TARGET:$REMOTEDIR/