From 106c2cbc34bdfe4f9b42c3e0856226eab6d32d60 Mon Sep 17 00:00:00 2001 From: Radar231 Date: Sat, 11 Sep 2021 10:51:59 -0400 Subject: [PATCH] initial checkin --- README.md | 40 +++++++++++++++++++++++ backups/.placeholder | 0 bu-hosts/jmc.delfax.net | 1 + bu-lists/jmc.delfax.net_bu-list | 6 ++++ logs/.placeholder | 0 rem-bu | 58 +++++++++++++++++++++++++++++++++ 6 files changed, 105 insertions(+) create mode 100644 README.md create mode 100644 backups/.placeholder create mode 100644 bu-hosts/jmc.delfax.net create mode 100644 bu-lists/jmc.delfax.net_bu-list create mode 100644 logs/.placeholder create mode 100755 rem-bu diff --git a/README.md b/README.md new file mode 100644 index 0000000..9567683 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# remote_backups + +## Introduction + +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. + +The script is intended to be run from the crontab for a user that has root ssh +key access on the remote hosts. + +## Configuration + +* bu-hosts + +This directory contains a file for each remote host to be backed up. The filename +is the host's FQDN. + +The file for each host contains the SSH specification for reaching that host. + +* bu-lists + +This directory contains a file for each remote host to be backed up. The filename +is the host's FQDN, with "_bu-list" appended. + +The file for each host contain a list of directories on the remote host to be backed +up, one directory per line. + +## Dir List + +``` +remote_backups +├── backups +├── bu-hosts +├── bu-lists +└── logs +``` diff --git a/backups/.placeholder b/backups/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/bu-hosts/jmc.delfax.net b/bu-hosts/jmc.delfax.net new file mode 100644 index 0000000..b400107 --- /dev/null +++ b/bu-hosts/jmc.delfax.net @@ -0,0 +1 @@ +ssh -p xxxx diff --git a/bu-lists/jmc.delfax.net_bu-list b/bu-lists/jmc.delfax.net_bu-list new file mode 100644 index 0000000..a44f279 --- /dev/null +++ b/bu-lists/jmc.delfax.net_bu-list @@ -0,0 +1,6 @@ +/etc +/usr/local/bin +/usr/local/etc +/home +/opt/docker +/opt/bin diff --git a/logs/.placeholder b/logs/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/rem-bu b/rem-bu new file mode 100755 index 0000000..56f187c --- /dev/null +++ b/rem-bu @@ -0,0 +1,58 @@ +#!/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