Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # save your bash file in "bin" folder
- # you need to fill Database credentials
- user="root"
- password=""
- host=""
- db_name=""
- #backup folder
- backup_path="/home/user/dbbackups"
- #date
- #date=$(date +"%d-%b-%Y")
- date=$(date "+%Y.%m.%d-%H.%M.%S")
- # Set default file permissions
- umask 177
- # Dump database into SQL file
- mysqldump --user=$user --password=$password --host=$host $db_name > $backup_path/$db_name-$date.sql
- # Delete files older than 7 days
- find $backup_path/* -mtime +7 -exec rm {} \;
- # send email
- subject="Database backup success"
- body="This email was sent using a kyawnaingtun's bash script. Folder path is $backup_path/$db_name-$date.sql"
- from=""
- to="youremail@gmail.com"
- #you@example.com other@example.com
- fileAttachment="$backup_path/$db_name-$date.sql"
- echo "Sending email..."
- echo "$body" | mail -s "$subject" $to
- echo "Email sent to: $to"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement