#!/bin/bash # # Copy a site backup between servers. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public # License along with this program. If not, see # . # Load. source $APP_BASE/lib/hydra/functions || exit 1 hydra_config_load # Basic parameters. SITES="/var/sites" DEST="$1" SITE="$2" DATE="`date +%Y%m%d`" ORIG="$SITES/backups/site/$SITE/`facter hostname`" # Syntax check. if [ -z "$SITE" ]; then hydra_action_usage exit 1 fi # Ensure we have a recent local backup. if [ ! -d "$ORIG/$DATE" ]; then echo "Backup for $SITE at $DATE not found, creating one..." hydractl site-backup $SITE fi # Parse server name and port. if echo $DEST | grep -q ":"; then SERVER="`echo $DEST | cut -d : -f 1`" PORT="`echo $DEST | cut -d : -f 2`" else SERVER="$DEST" fi # Ensure we have a port. if [ -z "$PORT" ]; then PORT="22" fi # Create destination folder. echo "Login in to remote server to create remote folder..." ssh -p $PORT backups@$SERVER mkdir -p $ORIG # Sync to remote destination. echo "Copying backup..." rsync -avz -e "ssh -p $PORT" $ORIG/ backups@$SERVER:/$ORIG/