initial checkin
This commit is contained in:
commit
106c2cbc34
|
@ -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
|
||||||
|
```
|
|
@ -0,0 +1 @@
|
||||||
|
ssh -p xxxx
|
|
@ -0,0 +1,6 @@
|
||||||
|
/etc
|
||||||
|
/usr/local/bin
|
||||||
|
/usr/local/etc
|
||||||
|
/home
|
||||||
|
/opt/docker
|
||||||
|
/opt/bin
|
|
@ -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
|
Loading…
Reference in New Issue