Guest User

Untitled

a guest
Mar 20th, 2019
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. #this is the prefix before the filename and can be anything you want
  4. fileprefix='mysql_backup_';
  5.  
  6. #this is your mysql user - best to create a new mysql user called backup that has access to all databases
  7. myuser='backup';
  8.  
  9. #your mysql password
  10. mypass='s0mething$ecure123';
  11.  
  12. #the backup directory that you should put at the root, not public_html
  13. #chmod 644 the backup folder and leave the trailing slash
  14. backupdir='/home/{typically your main cpanel account here without brackets}/backup/';
  15.  
  16. #more emails can be added by using a , to separate
  17. emailto='test@test.com';
  18.  
  19. #subject of the email
  20. emailsubject='mysql backup';
  21.  
  22. #body of the email
  23. emailbody='mysql db backup attached';
  24.  
  25. #shouldn't need to change below this
  26. date=`date '+%Y-%m-%d'`;
  27. file=$fileprefix$date.gz;
  28.  
  29. mysqldump -u$myuser -p$mypass --all-databases | gzip > $backupdir$file;
  30. find $backupdir -name "$fileprefix*" -mtime +7 -type f -exec rm -rf {} ;
  31. echo $emailbody | mutt -s "$emailsubject" -a $backupdir$file "$emailto";
Add Comment
Please, Sign In to add comment