initial checkin

This commit is contained in:
Radar231 2021-07-22 23:14:55 -04:00
commit 2a10682a54
7 changed files with 220 additions and 0 deletions

26
files/du-all-check Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
buuser="buuser"
remhost="files.lan"
rembase="/volumeUSB1/usbshare/rsync-backups"
hosts=$(ssh ${buuser}@${remhost} ls -d ${rembase}/* | cut -d'/' -f5 | grep "_backups")
for i in $hosts
do
backups=$(ssh ${buuser}@${remhost} ls -d ${rembase}/${i}/* | cut -d'/' -f6)
for j in $backups
do
budst="rsync://${buuser}@${remhost}//${rembase}/${i}/${j}"
echo "Backup: ${i}/${j}"
echo ">>>>>>>>>>>>>=============<<<<<<<<<<<<<"
echo ""
/usr/bin/duplicity --no-encryption collection-status ${budst}
echo ""
done
cd ..
done

34
files/du-bu Executable file
View File

@ -0,0 +1,34 @@
#!/bin/bash
bulist="/usr/local/etc/du-list"
logdir="/usr/local/log"
curhost=$(hostname)
remhost="files.lan"
rembase="/volumeUSB1/usbshare/rsync-backups/${curhost}_backups"
buuser="buuser"
budst="rsync://${buuser}@${remhost}//${rembase}"
echo "Backup run for ${curhost} beginning at $(date +%Y%m%d-%H%M%S)" >> ${logdir}/duplicity_run.log
list=$(cat ${bulist})
for i in $list
do
buname=$(echo $i | sed 's/\//_/g' | sed 's/^_//g')
bulog="${logdir}/duplicity_${buname}_$(date +%Y%m%d-%H%M%S)_run.log"
ssh ${buuser}@${remhost} mkdir -p ${rembase}/${buname}
if [ ! -z $1 ];
then
echo "$(date +%H%M%S): Doing full backup of ${i}" >> ${logdir}/duplicity_run.log
/usr/bin/duplicity full --no-encryption --name ${buname} $i ${budst}/${buname} 2>&1 >> ${bulog}
else
echo "$(date +%H%M%S): Doing incremental backup of ${i}" >> ${logdir}/duplicity_run.log
/usr/bin/duplicity --no-encryption --name ${buname} $i ${budst}/${buname} 2>&1 >> ${bulog}
fi
done
echo "Backup run completed at $(date +%Y%m%d-%H%M%S)" >> ${logdir}/duplicity_run.log

25
files/du-check Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
bulist="/usr/local/etc/du-list"
curhost=$(hostname)
buuser="buuser"
remhost="files.lan"
rembase="/volumeUSB1/usbshare/rsync-backups/${curhost}_backups"
budst="rsync://${buuser}@${remhost}//${rembase}"
buList=$(cat ${bulist})
for i in $buList
do
buname=$(echo $i | sed 's/\//_/g' | sed 's/^_//g')
echo "Backup: ${buname}"
echo ">>>>>>>>>>>>>=============<<<<<<<<<<<<<"
echo ""
/usr/bin/duplicity --no-encryption collection-status ${budst}/${buname}
echo ""
done

27
files/du-clean Executable file
View File

@ -0,0 +1,27 @@
#!/bin/bash
bulist="/usr/local/etc/du-list"
logdir="/usr/local/log"
curhost=$(hostname)
buuser="buuser"
remhost="files.lan"
rembase="/volumeUSB1/usbshare/rsync-backups/${curhost}_backups"
budst="rsync://${buuser}@${remhost}//${rembase}"
curDay=$(date +%d)
echo "Duplicity cleanup run for ${curhost} beginning at $(date +%Y%m%d-%H%M%S)" >> ${logdir}/duplicity_cleanup_run.log
list=$(cat ${bulist})
for i in $list
do
buname=$(echo $i | sed 's/\//_/g' | sed 's/^_//g')
bulog="${logdir}/duplicity_${buname}_$(date +%Y%m%d-%H%M%S)_cleanup_run.log"
/usr/bin/duplicity remove-all-but-n-full 2 --force --no-encryption ${budst}/${buname} 2>&1 >> ${bulog}
done
echo "Duplicity cleanup run completed at $(date +%Y%m%d-%H%M%S)" >> ${logdir}/duplicity_cleanup_run.log

5
files/du-list Normal file
View File

@ -0,0 +1,5 @@
/etc
/home/rmorrow
/root
/usr/local/bin
/usr/local/etc

11
files/du-wrapper Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
curDay=$(date +%d)
if [[ "${curDay}" -eq "1" ]];
then
/usr/local/bin/du-bu full
else
/usr/local/bin/du-bu
fi

92
tasks/main.yml Normal file
View File

@ -0,0 +1,92 @@
---
###########################################################################
#
# This role will set up our duplicity backup configuration.
#
###########################################################################
# tasks file for du_backup
- debug: msg="Setting up duplicity backups (du-bu)"
############################################################
- name: Make sure duplicity package is installed
apt:
name: duplicity
state: latest
############################################################
- name: Create /usr/local/log directory
file:
path: "/usr/local/log"
state: directory
owner: "root"
group: "root"
mode: "0755"
############################################################
- name: Copy files to /usr/local/bin
copy:
src: "files/{{ item }}"
dest: "/usr/local/bin/{{ item }}"
owner: "root"
group: "root"
mode: "0755"
loop:
- du-bu
- du-check
- du-all-check
- du-clean
- du-wrapper
############################################################
- name: Copy du-list to /usr/local/etc (if it doesn't exist)
copy:
src: "files/du-list"
dest: "/usr/local/etc/du-list"
owner: "root"
group: "root"
mode: "0644"
force: false
############################################################
- name: Add backup entry to root crontab
cron:
name: "Daily backup - full back on 1st of the month, incremental otherwise"
minute: "00"
hour: "01"
job: "/usr/local/bin/du-wrapper >>/usr/local/log/duplicity_cron_run.log 2>&1 &"
############################################################
- name: Add cleanup entry to root crontab
cron:
name: "Monthly cleanup of old backups"
minute: "00"
hour: "10"
day: "01"
job: "/usr/local/bin/du-clean >>/usr/local/log/duplicity_cron_run.log 2>&1 &"
############################################################
- name: Generate ssh keys for root user (if they dont already exist)
openssh_keypair:
path: "/root/.ssh/id_rsa"
comment: "root@{{ ansible_hostname }}"
owner: "root"
group: "root"
force: false
regenerate: never
############################################################
- name: Display root public ssh key
command: "cat /root/.ssh/id_rsa.pub"
register: command_output
############################################################
- name: Print message and ssh key
debug:
msg:
- "Copy the following public ssh key to the buuser authorized_keys file on the backup server host:"
- ""
- "{{ command_output.stdout }}"
- ""
# EOF