#!/bin/bash ##################################################################### # # rem-bu # # A simple shell script to retrieve selected remote server directories # in order to integrate the remote files into the local homelab # backup solution. # # Rsync is used so that only changed files are retrieved on subsequent # runs of the backup script. # ##################################################################### # Directory variables buDir="/opt/remote_backups" buLogDir="${buDir}/logs" buHosts="${buDir}/bu-hosts" buLists="${buDir}/bu-lists" # current date/time for logfile curDate=$(date +"%Y%m%d-%H%M%S") # list of remote hosts to backup hostList=$(ls -1 ${buHosts}/.) # loop through for each host for host in $hostList do # host specific variables buSSH=$(cat ${buHosts}/${host}) buList=$(cat ${buLists}/${host}_bu-list) buHostDir="${buDir}/backups/${host}" buHostLog="${host}_${curDate}.log" # create host directory if required if [ ! -d "$buHostDir" ] then mkdir -p $buHostDir fi # loop through backup directories for current host for i in $buList do dstDir="${buHostDir}${i}" # create current dir backup path if required if [ ! -d "$dstDir" ] then mkdir -p $dstDir fi # rsync remote files to local backup dir rsync -av -e "${buSSH}" --delete root@${host}:${i}/* ${dstDir}/ >>${buLogDir}/${buHostLog} 2>&1 done done # EOF