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) hostname=$(hostname -s)
archive_file="$hostname-$day.tgz" archive_file="$hostname-$day.tgz"
#Telegram details
api=bot api
chatid=chat id info
#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"
@ -30,67 +26,62 @@ user="root"
password="change.me" password="change.me"
db_name="fulldbbackup" db_name="fulldbbackup"
#Telegram details
api=bot api
chatid=chat id info
#ssh info #ssh info
suser="user" suser="user"
shost="host" shost="host/ip"
sloc="ssh host location" sloc="backup remote location"
# Print start status message. # 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. # Backup the files using tar.
tar czvfP $dest/$archive_file $backup_files tar czvfP $dest/$archive_file $backup_files
# Print end status message. # 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 # 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 scp $dest/$archive_file $suser@$shost:$sloc
#finished copy #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" 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"
#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"
#Start database backup #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 #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 mysqldump --user=$user --events --ignore-table=mysql.event --password=$password --all-databases > $dest/$db_name-$date.sql
#make tar #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 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 # 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 scp $dest/$sql_file $suser@$shost:$sloc
#delete sql tar file uname -onr >> /tmp/backup/info1
rm $dest/$sql_file
uname -a >> /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`
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/info1
rm /tmp/backup/info2 rm /tmp/backup/info2
#done #done