update script for restic

This commit is contained in:
infernvs 2017-11-13 16:29:44 +00:00 committed by GitHub
parent 353d9caf35
commit c6819226f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 57 deletions

View File

@ -1,88 +1,64 @@
#!/bin/bash #!/bin/csh
#################################### #######################################
# # #
# Backup script. # Backup script for FreeBSD #
# # using restic & telegram messages #
#################################### # #
#######################################
# What to backup. # Folders to backup
backup_files="/usr/home /usr/local/etc/apache24 /usr/local/etc/namedb" backup_files="/usr/home /usr/local/etc/apache24 /usr/local/etc/namedb /usr/local/etc/squid"
# Where to backup to. # Where to backup.
dest="/tmp/backup" dest="change-me"
sshuser="user"
sshhost="host/ip"
# Create archive filename. #Telegram details
day=`date +%d-%b-%Y` api=bot-api
hostname=$(hostname -s) chatid=chat-id
archive_file="$hostname-$day.tgz" url="https://api.telegram.org/bot$api/sendMessage"
#Archive Filename #Archive Filename
date=`date +%d-%b-%Y` date=`date +%d-%b-%Y`
sql_file="sql_backup-$date.tgz" sql_file="sql_backup-$date.tgz"
src_dir="/tmp/backup" src_dir="/tmp/backup"
tmp_dir="/tmp/backup"
#Database info #Database info
user="root" user="user"
password="change.me" password="mysql_password"
db_name="fulldbbackup" 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. # Print start status message.
curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="Backing up <b>$backup_files</b> to <b>$dest/$archive_file</b>" curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="Backing up <b>$backup_files</b> to <b>$sshhost/$dest</b>"
# Backup the files using tar. #starting backup
tar czvfP $dest/$archive_file $backup_files restic -r sftp:$sshuser@$sshhost:$dest -p /root/pw backup $backup_files
# Print end status message. mysqldump --user=$user --events --ignore-table=mysql.event --password=$password --all-databases > $tmp_dir/$db_name-$date.sql
curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="Backup finished at <b>$dest/$archive_file</b>"
# Copy over ssh tar -cpzf $tmp_dir/$sql_file --directory=/ --exclude=proc --exclude=sys --exclude=dev/pts --exclude=$tmp_dir $src_dir
curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="Copy backup <b>$archive_file</b> to orangepi"
scp $dest/$archive_file $suser@$shost:$sloc restic -r sftp:$sshuser@$sshhost:$dest -p /root/pw backup $src_dir/$sql_file
#finished copy restic -r sftp:$sshuser@$sshhost:$dest -p /root/pw forget --keep-last 1
curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="Backup <b>$archive_file<b> to orangepi complete"
#Start database backup restic -r sftp:$sshuser@$sshhost:$dest -p /root/pw snapshots >> /tmp/backup/ss
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
uname -onr >> /tmp/backup/info1 uname -onr >> /tmp/backup/info1
uptime >> /tmp/backup/info2 uptime >> /tmp/backup/info2
uname=`cat /tmp/backup/info1` uname=`cat /tmp/backup/info1`
uptime=`cat /tmp/backup/info2` 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 <b>$uname</b> is <b>$uptime</b>. All backups complete, good bye! :)" curl -s -X POST $url -d chat_id=$chatid -d parse_mode="HTML" -d text="<b>Current backups</b>%0A %0A $snapshots%0A %0A Current uptime of %0A <b>$uname</b> is %0A %0A <b>$uptime</b>"
#delete files #delete files
rm $dest/$archive_file rm /tmp/backup/$db_name-$date.sql
rm $dest/$db_name-$date.sql rm /tmp/backup/$sql_file
rm $dest/$sql_file
rm /tmp/backup/info1 rm /tmp/backup/info1
rm /tmp/backup/info2 rm /tmp/backup/info2
rm /tmp/backup/ss
#done #done