Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #this is the prefix before the filename and can be anything you want
- fileprefix='mysql_backup_';
- #this is your mysql user - best to create a new mysql user called backup that has access to all databases
- myuser='backup';
- #your mysql password
- mypass='s0mething$ecure123';
- #the backup directory that you should put at the root, not public_html
- #chmod 644 the backup folder and leave the trailing slash
- backupdir='/home/{typically your main cpanel account here without brackets}/backup/';
- #more emails can be added by using a , to separate
- emailto='test@test.com';
- #subject of the email
- emailsubject='mysql backup';
- #body of the email
- emailbody='mysql db backup attached';
- #shouldn't need to change below this
- date=`date '+%Y-%m-%d'`;
- file=$fileprefix$date.gz;
- mysqldump -u$myuser -p$mypass --all-databases | gzip > $backupdir$file;
- find $backupdir -name "$fileprefix*" -mtime +7 -type f -exec rm -rf {} ;
- echo $emailbody | mutt -s "$emailsubject" -a $backupdir$file "$emailto";
Add Comment
Please, Sign In to add comment