Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. # save your bash file in "bin" folder
  2.  
  3. # you need to fill Database credentials
  4. user="root"
  5. password=""
  6. host=""
  7. db_name=""
  8.  
  9. #backup folder
  10. backup_path="/home/user/dbbackups"
  11. #date
  12. #date=$(date +"%d-%b-%Y")
  13. date=$(date "+%Y.%m.%d-%H.%M.%S")
  14. # Set default file permissions
  15. umask 177
  16. # Dump database into SQL file
  17. mysqldump --user=$user --password=$password --host=$host $db_name > $backup_path/$db_name-$date.sql
  18. # Delete files older than 7 days
  19. find $backup_path/* -mtime +7 -exec rm {} \;
  20. # send email
  21. subject="Database backup success"
  22. body="This email was sent using a kyawnaingtun's bash script. Folder path is $backup_path/$db_name-$date.sql"
  23. from=""
  24. to="youremail@gmail.com"
  25. #you@example.com other@example.com
  26. fileAttachment="$backup_path/$db_name-$date.sql"
  27.  
  28. echo "Sending email..."
  29.  
  30. echo "$body" | mail -s "$subject" $to
  31.  
  32. echo "Email sent to: $to"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement