#!/bin/bash MAILFILE="/tmp/mailtxt" SERVER_NAME=$HOSTNAME SENDER=$(whoami) USER="noreply" MAILHEADER="/opt/b2backup/mailheader.txt" MAILFOOTER="/opt/b2backup/mailfooter.txt" . ${PWD}/config.txt export B2_ACCOUNT_ID="$B2_ACCOUNT_ID" export B2_ACCOUNT_KEY="$B2_ACCOUNT_KEY" export RESTIC_REPOSITORY="$RESTIC_REPOSITORY" export RESTIC_PASSWORD_FILE="$RESTIC_PASSWORD_FILE" #dump dbs: #Uncomment double-commented lines to enable dumping of all MySQL databases, MySQL auth is up to you to configure. #remove old dumps ##find /backup/sqldumps -type f -mtime +7 | xargs rm -f #backup dbs to one massive file ##/usr/bin/mysqldump -u root --single-transaction --quick --lock-tables=false --all-databases > /backup/sqldumps/full-backup-$(date +"%Y-%m-%d_%H-%M-%S").sql #backup dbs to separate files ##for DB in $(mysql -e 'show databases' -s --skip-column-names); do ## mysqldump $DB > "/backup/sqldumps/$DB-$(date +"%Y-%m-%d_%H-%M-%S").sql"; ##done /usr/bin/restic backup $BACKUPDATA /usr/bin/restic forget --keep-last $KEEPLAST --keep-daily $KEEPDAILY --keep-weekly $KEEPWEEKLY --keep-monthly $KEEPMONTHLY --keep-yearly $KEEPYEARLY echo "Backup Complete. Currently available snapshots:" > $MAILFILE echo "
" >> $MAILFILE
echo "$(/usr/bin/restic snapshots)" >> $MAILFILE


(
	echo "Subject: $EMAILSUB"
	echo "From: $SENDER"
	echo "To: $RECIPIENT"
	cat $MAILHEADER $MAILFILE $MAILFOOTER
) | sendmail -t 

rm $MAILFILE

for var in $(awk -F"=" '{print $1}' ${PWD}/config.txt); do
    unset $var
done