Last active
June 24, 2019 11:22
-
-
Save faizalmansor/43e02a9904ec1ef6de7f040486959049 to your computer and use it in GitHub Desktop.
Script to automate local backup for files & database with email notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script : ost-local-backup-w-email.sh | |
# Author : Osh <[email protected]> | |
# Title : Osh local backup with email notification | |
# Description: Script to automate local backup for files & database with email notification | |
# Target OS : Centos 7 | |
# Create archive of target folder | |
today=`date '+%Y%m%d_%H%M%S'`; | |
############################################################################ | |
# SETTING FOR BACKUP FOLDER & DATABASE | |
# Change these to your project backup directory/folder & database | |
# | |
var_backup_filename="/path/to/backup/backup_$today.tar.gz" | |
var_folder_to_backup="/path/to/project_folder/" | |
var_db_to_backup="project_database_name" | |
var_backup_sqlname="/path/to/backup/backup_$today.sql" | |
############################################################################ | |
tar -czvf "$var_backup_filename" "$var_folder_to_backup" | |
############################################################################ | |
# I M P O R T A N T ! ! ! | |
############################################################################ | |
# | |
# Define the following ~/.my.cnf: | |
# | |
# [mysqldump] | |
# host = your_MySQL_server_name_or_IP | |
# port = 3306 | |
# user = database_user_name | |
# password = database_password | |
############################################################################ | |
# Create sqldump of target database | |
mysqldump "$var_db_to_backup" > "$var_backup_sqlname" | |
############################################################################ | |
# SETTING FOR EMAIL: | |
# | |
var_email_title="Backup on RnD2 Completed" | |
var_email_body="Project folder and database backup completed successful." | |
############################################################################ | |
set -e; | |
echo "$var_email_body" | mailx -s "$var_email_title" [email protected] || : | |
echo 'Completed' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Change
YOUR_GMAIL
to your actual email address to receive the notification.