You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hetzner-ansible/roles/backup/files/pull_remote_backups.sh

23 lines
672 B
Bash

#!/bin/bash
#
#
#
# Define some variables
REMOTE_SYSTEM_USER=backupuser
DATABASE_SERVER_IP=$1
STAGE=$2
DATABASE_ENGINE=$3
DEST_DIR=${HOME}/backups/${STAGE}/${DATABASE_ENGINE}
# Exit on ${DEST_DIR} not found
[ ! -d "$DEST_DIR" ] && exit 1
# Remove files oder than 48h in ${DEST_DIR}
find $DEST_DIR -type d -mtime +1 -print0 | xargs -I OLD_DIR -0 rm -rf "OLD_DIR"
[ "$?" != "0" ] && exit 1
# Create backup directory ${DEST_DIR} if not exist and rsync from ${DATABASE_SERVER_IP} to ${DEST_DIR}/
mkdir -p ${DEST_DIR}
rsync -av --remove-source-files -e "ssh -o StrictHostKeyChecking=no" ${REMOTE_SYSTEM_USER}@${DATABASE_SERVER_IP}:/backups/${DATABASE_ENGINE}/ ${DEST_DIR}/