Update backup.sh

This commit is contained in:
infernvs 2017-10-18 16:32:35 +01:00 committed by GitHub
parent 228261c551
commit 96994de1d4
1 changed files with 22 additions and 31 deletions

View File

@ -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 <b>$backup_files</b> to <b>$dest/$archive_file</b>"
# 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 <b>$dest/$archive_file</b>"
# 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 <b>$archive_file</b> 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 <b>$archive_file<b> 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 <b>$uname</b> is <b>$uptime</b>. 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
#done