From 96994de1d4ed0131b7cd744d826676028d37a70a Mon Sep 17 00:00:00 2001 From: infernvs Date: Wed, 18 Oct 2017 16:32:35 +0100 Subject: [PATCH] Update backup.sh --- backup.sh | 53 ++++++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/backup.sh b/backup.sh index ad811c4..ed88cb3 100644 --- a/backup.sh +++ b/backup.sh @@ -16,10 +16,6 @@ day=`date +%d-%b-%Y` hostname=$(hostname -s) archive_file="$hostname-$day.tgz" -#Telegram details -api=bot api -chatid=chat id info - #Archive Filename date=`date +%d-%b-%Y` sql_file="sql_backup-$date.tgz" @@ -30,67 +26,62 @@ user="root" password="change.me" db_name="fulldbbackup" +#Telegram details +api=bot api +chatid=chat id info + #ssh info suser="user" -shost="host" -sloc="ssh host location" +shost="host/ip" +sloc="backup remote location" # Print start status message. -curl -s -X POST https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d text="Backing up $backup_files to $dest/$archive_file" +curl -s -X POST https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d parse_mode="HTML" -d text="Backing up $backup_files to $dest/$archive_file" # Backup the files using tar. tar czvfP $dest/$archive_file $backup_files # Print end status message. -curl -s -X POST https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d text="Backup finished at $dest/$archive_file" - +curl -s -X POST https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d parse_mode="HTML" -d text="Backup finished at $dest/$archive_file" # Copy over ssh -curl -s -X POST https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d text="Copy backup $archive_file to orangepi" +curl -s -X POST https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d parse_mode="HTML" -d text="Copy backup $archive_file to orangepi" scp $dest/$archive_file $suser@$shost:$sloc #finished copy -curl -s -X POST https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d text="Backup $archive_file to orangepi complete" - -#delete tmp -rm $dest/$archive_file - -#done -curl -s -X POST https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d text="Backups complete" +curl -s -X POST https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d parse_mode="HTML" -d text="Backup $archive_file to orangepi complete" #Start database backup -curl -s -X POST https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d text="Starting SQL Backup" - +curl -s -X POST https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d parse_mode="HTML" -d text="Starting SQL Backup" #dump database -curl -s -X POST https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d text="dump database" +curl -s -X POST https://api.telegram.org/bot$api/sendMessage -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 https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d text="Backup the files using tar." +curl -s -X POST https://api.telegram.org/bot$api/sendMessage -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 -#delete sql file -rm $dest/$db_name-$date.sql - # Copy over ssh -curl -s -X POST https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d text="Copy backup to orangepi" +curl -s -X POST https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d parse_mode="HTML" -d text="Copy backup to orangepi" scp $dest/$sql_file $suser@$shost:$sloc -#delete sql tar file -rm $dest/$sql_file - -uname -a >> /tmp/backup/info1 +uname -onr >> /tmp/backup/info1 uptime >> /tmp/backup/info2 uname=`cat /tmp/backup/info1` uptime=`cat /tmp/backup/info2` -curl -s -X POST https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d text="Current uptime of $uname is $uptime. All backups complete, good bye! :)" +curl -s -X POST https://api.telegram.org/bot$api/sendMessage -d chat_id=$chatid -d parse_mode="HTML" -d text="Current uptime of $uname is $uptime. All backups complete, good bye! :)" + +#delete files +rm $dest/$archive_file +rm $dest/$db_name-$date.sql +rm $dest/$sql_file rm /tmp/backup/info1 rm /tmp/backup/info2 -#done \ No newline at end of file +#done