From c6819226f8d2801f88d68d4bc6826088643de06c Mon Sep 17 00:00:00 2001 From: infernvs Date: Mon, 13 Nov 2017 16:29:44 +0000 Subject: [PATCH] update script for restic --- backup.sh | 90 ++++++++++++++++++++----------------------------------- 1 file changed, 33 insertions(+), 57 deletions(-) diff --git a/backup.sh b/backup.sh index 184ca63..666142c 100644 --- a/backup.sh +++ b/backup.sh @@ -1,88 +1,64 @@ -#!/bin/bash -#################################### -# -# Backup script. -# -#################################### +#!/bin/csh +####################################### +# # +# Backup script for FreeBSD # +# using restic & telegram messages # +# # +####################################### -# What to backup. -backup_files="/usr/home /usr/local/etc/apache24 /usr/local/etc/namedb" +# Folders to backup +backup_files="/usr/home /usr/local/etc/apache24 /usr/local/etc/namedb /usr/local/etc/squid" -# Where to backup to. -dest="/tmp/backup" +# Where to backup. +dest="change-me" +sshuser="user" +sshhost="host/ip" -# Create archive filename. -day=`date +%d-%b-%Y` -hostname=$(hostname -s) -archive_file="$hostname-$day.tgz" +#Telegram details +api=bot-api +chatid=chat-id +url="https://api.telegram.org/bot$api/sendMessage" #Archive Filename date=`date +%d-%b-%Y` sql_file="sql_backup-$date.tgz" src_dir="/tmp/backup" +tmp_dir="/tmp/backup" #Database info -user="root" -password="change.me" +user="user" +password="mysql_password" db_name="fulldbbackup" -#Telegram details -api=bot api -chatid=chat id info -url="https://api.telegram.org/bot$api/sendMessage" - -#ssh info -suser="user" -shost="host/ip" -sloc="backup remote location" - # Print start status message. -curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="Backing up $backup_files to $dest/$archive_file" +curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="Backing up $backup_files to $sshhost/$dest" -# Backup the files using tar. -tar czvfP $dest/$archive_file $backup_files +#starting backup +restic -r sftp:$sshuser@$sshhost:$dest -p /root/pw backup $backup_files -# Print end status message. -curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="Backup finished at $dest/$archive_file" +mysqldump --user=$user --events --ignore-table=mysql.event --password=$password --all-databases > $tmp_dir/$db_name-$date.sql -# Copy over ssh -curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="Copy backup $archive_file to orangepi" +tar -cpzf $tmp_dir/$sql_file --directory=/ --exclude=proc --exclude=sys --exclude=dev/pts --exclude=$tmp_dir $src_dir -scp $dest/$archive_file $suser@$shost:$sloc +restic -r sftp:$sshuser@$sshhost:$dest -p /root/pw backup $src_dir/$sql_file -#finished copy -curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="Backup $archive_file to orangepi complete" +restic -r sftp:$sshuser@$sshhost:$dest -p /root/pw forget --keep-last 1 -#Start database backup -curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="Starting SQL Backup" - -#dump database -curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="dump database" - -mysqldump --user=$user --events --ignore-table=mysql.event --password=$password --all-databases > $dest/$db_name-$date.sql - -#make tar -curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="Backup the files using tar." - -tar -cpzf $dest/$sql_file --directory=/ --exclude=proc --exclude=sys --exclude=dev/pts --exclude=$dest $src_dir - -# Copy over ssh -curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="Copy backup to orangepi" - -scp $dest/$sql_file $suser@$shost:$sloc +restic -r sftp:$sshuser@$sshhost:$dest -p /root/pw snapshots >> /tmp/backup/ss uname -onr >> /tmp/backup/info1 uptime >> /tmp/backup/info2 uname=`cat /tmp/backup/info1` uptime=`cat /tmp/backup/info2` +snapshots=`cat /tmp/backup/ss` -curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="Current uptime of $uname is $uptime. All backups complete, good bye! :)" +curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="Current backups%0A %0A $snapshots%0A %0A Current uptime of %0A $uname is %0A %0A $uptime" #delete files -rm $dest/$archive_file -rm $dest/$db_name-$date.sql -rm $dest/$sql_file +rm /tmp/backup/$db_name-$date.sql +rm /tmp/backup/$sql_file rm /tmp/backup/info1 rm /tmp/backup/info2 +rm /tmp/backup/ss #done