#!/bin/bash ####################################################################### #Script Name: all_backup_post #Version: 1.5 #Description: Script to rclone backup to AWS for Deboan. #Last Modify Date: 01062021 #Author:Brent Dacus #Email:brent[at]thedacus[dot]net ####################################################################### # Variables # ####################################################################### #local backup locations mailtoaddress="tech@delainhosting.com" mailfromaddress="tech@delainhosting.com" admin=/admin_backups system=/sys_backup host="$(hostname -s)" wom=$((($(date +%-d) - 1) / 7 + 1)) cb=/usr/local/directadmin/custombuild/build #remote backup dest remote=bb2 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 ${cb} mysql_backup printf "Backing up the %s directory on %s to %s.\n" "$admin" "$host" "$bucket" rclone sync $admin $remote:$bucket/$host$admin/$wom --log-level INFO --log-file $logfile if [ "$?" -eq 0 ]; then rclone check $admin $remote:$bucket/$host$admin/$wom --one-way --log-level INFO --log-file $logfile printf "Backing up Complete.\n" else date >>$logfile mail -s "System backup failed on server $host" -r "$mailfromaddress" "$mailtoaddress" <$logfile fi printf "Backing up the %s directory on %s to %s.\n" "$system" "$host" "$bucket" rclone sync $system $remote:$bucket/$host$system --log-level INFO --log-file $logfile if [ "$?" -eq 0 ]; then rclone check $system $remote:$bucket/$host$system --one-way --log-level INFO --log-file $logfile printf "Backing up Complete.\n" else date >>$logfile mail -s "System backup failed on server $host" -r "$mailfromaddress" "$mailtoaddress" <$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