#!/usr/local/bin/bash ####################################################################### #Script Name: all_backup_post #Version: 1.5 #Description: Script to rclone backup to AWS. #Last Modify Date: 01062021 #Author:Brent Dacus #Email:brent[at]thedacus[dot]net ####################################################################### # Variables # ####################################################################### #local backup locations admin=/admin_backups system=/sys_backup host="$(hostname -s)" wom=$((($(date +%-d) - 1) / 7 + 1)) rcarg="--ask-password=false --password-command" #remote backup dest remote=aws bucket="$(hostname -s)"rcbkup #logfile location logfile=/var/log/rclone/aws.log #file location export RCLONE_CONFIG_PASS=/usr/local/bin/passwd.txt #exit if running if [[ $(pidof -x "$(basename "$0")" -o %ppid) ]]; then exit; fi /usr/local/bin/rclone sync $admin $remote:$bucket/$host$admin/$wom --log-level INFO --log-file $logfile if [ "$?" -eq 0 ]; then /usr/local/bin/rclone check $admin $remote:$bucket/$host$admin/$wom --one-way --log-level INFO --log-file $logfile else date >>$logfile mail -s "Admin backup failed on server $(hostname -f)" tech@delainhosting.com <$logfile fi /usr/local/bin/rclone sync $system $remote:$bucket/$host$system --log-level INFO --log-file $logfile if [ "$?" -eq 0 ]; then /usr/local/bin/rclone check $system $remote:$bucket/$host$system --one-way --log-level INFO --log-file $logfile else date >>$logfile mail -s "System backup failed on server $(hostname -f)" tech@delainhosting.com <$logfile fi find $admin -mindepth 1 -type d -mtime 2 | xargs rm -rf #find $system -type f -printf '%t@\t%p\n' | sort -t $'\t' -g | head -n -2 | cut -d $'\t' -f 2- | xargs rm -f # reset credentials unset rclone_config_pass exit 0