diff --git a/b2backup.sh b/b2backup.sh new file mode 100644 index 0000000..b59a6fb --- /dev/null +++ b/b2backup.sh @@ -0,0 +1,44 @@ +#!/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 \ No newline at end of file diff --git a/b2mount.sh b/b2mount.sh new file mode 100644 index 0000000..277ba1a --- /dev/null +++ b/b2mount.sh @@ -0,0 +1,19 @@ +#!/bin/bash +. /opt/b2backup/b2config.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" +RESTOREDIR="$RESTORE_DIR" + +mkdir -p $RESTOREDIR +/usr/bin/restic mount $RESTOREDIR & +echo "Backups mounted to $RESTOREDIR" +echo "" +echo "Run umount $RESTOREDIR when finished" +echo "" + +for var in $(awk -F"=" '{print $1}' ${PWD}/config.txt); do + unset $var +done \ No newline at end of file diff --git a/config-example.txt b/config-example.txt new file mode 100644 index 0000000..6301c15 --- /dev/null +++ b/config-example.txt @@ -0,0 +1,17 @@ +EMAILSUB="SERVERANAME Backup Complete" +RECIPIENT="email@addre.ss" +BACKUPDATA="/path/to/dir1 /path/to/dir2 --exclude /path/to/exclude1 --exclude /path/to/exclude2" +KEEPLAST="7" +KEEPDAILY="0" +KEEPWEEKLY="4" +KEEPMONTHLY="2" +KEEPYEARLY="2" +B2_ACCOUNT_ID="" +B2_ACCOUNT_KEY="" +RESTIC_REPOSITORY="" +RESTIC_PASSWORD_FILE="/path/to/restic/password/file" +RESTORE_DIR="/path/to/mount/snapshot/repo" +VM_EMAILSUB="VM Backups Complete on SERVERNAME" +VM_XML_PATH="/path/to/backup/vm/xml" +VM_SNAP_PATH="/path/to/backup/vm/snapshots +VM_KEEP_BACKUP_DAYS="7" \ No newline at end of file diff --git a/mailfooter.txt b/mailfooter.txt new file mode 100644 index 0000000..dc684c5 --- /dev/null +++ b/mailfooter.txt @@ -0,0 +1,3 @@ ++