#!/bin/bash BACKUP_DIR=/mnt/opt/data/ SSH_HOST=cluster.univ@se.imbg.org.ua SSH_PORT=3322 RSYNC_DEST_BASE=/srv/backups/cluster.univ/opt 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-opt [ -f "$LOCK_FILE" ] && exit 0 trap "rm -f $LOCK_FILE" EXIT SIGINT SIGTERM touch "$LOCK_FILE" current_timestamp () { date +'%Y%m%d' } find_last_backup_script () { cat < $RSYNC_DEST_BASE/find_last_backup.sh" # execute the script to get last backup dir last_backup=$( ssh -p ${SSH_PORT} ${SSH_HOST} "/bin/bash $RSYNC_DEST_BASE/find_last_backup.sh" ) if [ -n "$last_backup" ]; then if [ "$last_backup" != "./$( current_timestamp )" ]; then RSYNC_LINK_DEST=" --link-dest=.${last_backup}" fi fi RSYNC_DEST_URL="${SSH_HOST}:${RSYNC_DEST_BASE}/$( current_timestamp )" changes=$( RSYNC_DRY_RUN=1 do_rsync ${BACKUP_DIR} ${RSYNC_DEST_URL} | wc -l ) if [ $changes -ne 0 ]; then do_rsync ${BACKUP_DIR} ${RSYNC_DEST_URL} fi