Script to automate remote backup of local mysql database
A script that runs locally on the MySQL server, dumps the MySQL database(s), and then automatically sends the backup offsite (remote server) for safe storage.
Key Features of this Script:
Dumps local MySQL database.
Compresses the dump.
Sends it securely to a remote backup server via scp.
# Transfer Backup Offsite via SCP scp -P $REMOTE_PORT$LOCAL_BACKUP_DIR/$ARCHIVE_NAME${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_DIR}/
if [ $? -eq 0 ]; then echo"[$(date)] Backup Successfully Transferred Offsite." | tee -a $LOG_FILE else echo"[$(date)] SCP Transfer Failed!" | tee -a $LOG_FILE exit 1 fi
# Cleanup Local Old Backups find $LOCAL_BACKUP_DIR -type f -mtime +$LOCAL_RETENTION_DAYS -delete
# Cleanup Remote Old Backups ssh -p $REMOTE_PORT${REMOTE_USER}@${REMOTE_HOST}"find ${REMOTE_DIR} -type f -mtime +${REMOTE_RETENTION_DAYS} -delete"
echo"[$(date)] MySQL Backup Completed Successfully." | tee -a $LOG_FILE