Skip to content

Instantly share code, notes, and snippets.

@StefanYohansson
Last active November 7, 2016 14:02
Show Gist options
  • Select an option

  • Save StefanYohansson/a3af2d4d26e1d94b28e13cd2fdc2b25c to your computer and use it in GitHub Desktop.

Select an option

Save StefanYohansson/a3af2d4d26e1d94b28e13cd2fdc2b25c to your computer and use it in GitHub Desktop.
backup scripts
#!/bin/sh
function send_backup {
rsync -r -z -c $1 [email protected]:/backups
if [ "$?" -eq "0" ]
then
rm -rf $1
echo "Rsync success." > $logfile_path/db_log.log
else
echo "Rsync fail." > $logfile_path/db_log.log
fi
}
function check_file_size {
if [ "$1" -eq "0" ]
then
echo "Backup empty." > $logfile_path/db_log.log
exit 1
fi
}
v_path=/etc/backup_jobs/db_backup
logfile_path=/var/log/backup_jobs
v_file_name=db_backup
MAILTO="[email protected]"
file_full_path=$v_path/$v_file_name`date +%Y-%m-%d`.sql
touch "$logfile_path/db_log.log"
mysqldump -uusername -ppassword -hlocalhost ddbname > $file_full_path
actualsize=$(wc -c <"$file_full_path")
if [ "$?" -eq 0 ]
then
check_file_size $actualsize
send_backup $file_full_path
mail -s "Backup has been done successfully" $MAILTO < $logfile_path/db_log.log
else
mail -s "Alert : Backup has been failed" $MAILTO < $logfile_path/db_log.log
exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment