From f5b01d6d7ad40fbea2c0467158b31689b3b4b3f4 Mon Sep 17 00:00:00 2001 From: Radar231 Date: Sun, 1 Aug 2021 19:40:48 -0400 Subject: [PATCH] Initial checkin --- README.md | 32 ++++++++++++++++++++++++++++++++ cron_entry.txt | 6 ++++++ du-all-check | 26 ++++++++++++++++++++++++++ du-bu | 34 ++++++++++++++++++++++++++++++++++ du-check | 25 +++++++++++++++++++++++++ du-clean | 27 +++++++++++++++++++++++++++ du-list | 5 +++++ du-wrapper | 11 +++++++++++ 8 files changed, 166 insertions(+) create mode 100644 README.md create mode 100644 cron_entry.txt create mode 100755 du-all-check create mode 100755 du-bu create mode 100755 du-check create mode 100755 du-clean create mode 100644 du-list create mode 100755 du-wrapper diff --git a/README.md b/README.md new file mode 100644 index 0000000..f719182 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# du_backups + +# Introduction + +This is a collection of scripts that I use to manage a duplicity based backup +solution. + +Configuration for the specific environment are located at the top of each +script. + +* du-bu + * The main backup script + +* du-check + * A script to examine the previously completed backups for the current + host only, on the destination server + +* du-all-check + * Similar to du-check, but checks backups from all hosts + +* du-clean + * A script to clean up backups from the destination server that are no + longer required + +* du-wrapper + * A simple wrapper script for calling du-bu from a crontab entry. This + script will perform a full backup on the first day of the month, and an + incremental backup on any other day. + +* du-list + * A list of directories to be backed up. + diff --git a/cron_entry.txt b/cron_entry.txt new file mode 100644 index 0000000..b1f07b1 --- /dev/null +++ b/cron_entry.txt @@ -0,0 +1,6 @@ +# Daily backup - full back on 1st of the month, incremental otherwise +00 01 * * * /usr/local/bin/du-wrapper >>/usr/local/log/duplicity_cron_run.log 2>&1 & + +# Monthly cleanup of old backups +00 10 01 * * /usr/local/bin/du-clean >>/usr/local/log/duplicity_cron_run.log 2>&1 & + diff --git a/du-all-check b/du-all-check new file mode 100755 index 0000000..23ed4c2 --- /dev/null +++ b/du-all-check @@ -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 + diff --git a/du-bu b/du-bu new file mode 100755 index 0000000..0551582 --- /dev/null +++ b/du-bu @@ -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 + diff --git a/du-check b/du-check new file mode 100755 index 0000000..4b90c35 --- /dev/null +++ b/du-check @@ -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 + + diff --git a/du-clean b/du-clean new file mode 100755 index 0000000..708d947 --- /dev/null +++ b/du-clean @@ -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 + diff --git a/du-list b/du-list new file mode 100644 index 0000000..a4daf78 --- /dev/null +++ b/du-list @@ -0,0 +1,5 @@ +/etc +/home/rmorrow +/root +/usr/local/bin +/usr/local/etc diff --git a/du-wrapper b/du-wrapper new file mode 100755 index 0000000..4496dc5 --- /dev/null +++ b/du-wrapper @@ -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 +