#!/bin/bash BACKUP_DIR=/home/ ROTATE_CNT=14 SSH_HOST=cluster.univ@se.imbg.org.ua SSH_PORT=3322 RSYNC_DEST_BASE=/srv/backups/cluster.univ/home RSYNC_EXCLUDE=${BACKUP_DIR}/.rsync_exclude RSYNC_SUDO=yes #RSYNC_VERBOSE=1 # backup from DRBD-master a-node only grep -q '/mnt/opt' /proc/mounts || exit 0 # lock in case of looooong backup LOCK_FILE=/run/lock/rsync-home [ -f "$LOCK_FILE" ] && exit 0 trap "rm -f $LOCK_FILE" EXIT SIGINT SIGTERM touch "$LOCK_FILE" rotation_script () { cat < .rotation_idx } if [ \$1 == "get" ]; then idx_get elif [ \$1 == "set" ]; then idx_set \$2 fi END } do_rsync () { local localdir=$1 local remotedir=$2 local verbosity="--quiet --no-motd" [ -n "${RSYNC_EXCLUDE}" ] && excludefile="--delete-excluded --exclude-from=${RSYNC_EXCLUDE}" [ -n "${RSYNC_VERBOSE}" ] && verbosity="--human-readable --progress" local rshcmd="ssh" [ -n "${SSH_PORT}" ] && rshcmd=ssh\ -p\ ${SSH_PORT} [ -n "${RSYNC_SUDO}" ] && rsyncpath=--rsync-path=sudo\ rsync [ -n "${RSYNC_DRY_RUN}" ] && dry_run=--dry-run\ --itemize-changes rsync --archive --links --recursive \ --hard-links --perms --owner --group \ --devices --specials --times --sparse \ --compress --compress-level=9 ${excludefile} \ --rsh="$rshcmd" "$rsyncpath" --delete ${dry_run} \ --numeric-ids ${verbosity} $RSYNC_LINK_DEST \ "${localdir}" "${remotedir}" } # put the simple script to manage /home rotation index rotation_script | ssh -p ${SSH_PORT} ${SSH_HOST} "cat > $RSYNC_DEST_BASE/rotation_idx.sh" # execute the script to get last rotation index (to set rsync link-dest) last_idx=$( ssh -p ${SSH_PORT} ${SSH_HOST} "/bin/bash $RSYNC_DEST_BASE/rotation_idx.sh get" ) if [ -n "$last_idx" ]; then RSYNC_LINK_DEST=" --link-dest=../$( printf %02d $last_idx )" fi # obtain next index to sync to next_idx=$(( $last_idx + 1 )) [ $next_idx -gt $ROTATE_CNT ] && next_idx=1 # rsync it RSYNC_DEST_URL="${SSH_HOST}:${RSYNC_DEST_BASE}/$( printf %02d $next_idx )" do_rsync ${BACKUP_DIR} ${RSYNC_DEST_URL} # increase saved index if [ $? -eq 0 ]; then ssh -p ${SSH_PORT} ${SSH_HOST} "/bin/bash $RSYNC_DEST_BASE/rotation_idx.sh set $next_idx" fi # RHEL GFS2 Guide reccommeds to drop caches to reduces the time required by other nodes # to regain ownership of their cluster locks/caches echo -n 3 >/proc/sys/vm/drop_caches