#!/bin/bash ####################################################################### #Script Name: all_backup_post #Version: 1.6 #Description: Script to rclone backup to AWS for Deboan. #Last Modify Date: 04092022 #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 printf "Backing up the databases on %s.\n" "$host" ${cb} mysql_backup printf "Successful databases are backed up.\n" printf "Backing up the %s directory on %s to %s.\n" "$admin" "$host" "$bucket" if rclone sync $admin $remote:$bucket/$host$admin/$wom --log-level INFO --log-file $logfile; then rclone check $admin $remote:$bucket/$host$admin/$wom --one-way --log-level INFO --log-file $logfile printf "Backup Complete.\n" printf "Backup Cleanup Starting.\n" rclone delete --min-age 7d $remote:$bucket printf "Backup Cleanup Complete.\n" else date >>$logfile mail -s "Admin backup FAILED on server $host" -r "$mailfromaddress" "$mailtoaddress" <$logfile fi printf "Backing up the %s directory on %s to %s.\n" "$system" "$host" "$bucket" if rclone sync $system $remote:$bucket/$host$system --log-level INFO --log-file $logfile; then rclone check $system $remote:$bucket/$host$system --one-way --log-level INFO --log-file $logfile printf "Backup 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 -exec rm -rf {} \; find $system/* -type f -mtime +7 -exec rm -rf {} \; unset rclone_config_pass exit 0