Pasikurkite backup.sh failą su sokiu turiniu:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| #!/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";
|
ir užsakykite CronJob. Šis skriptas autyomatiškai trina 7 dienų senumo backupus. Nustatykite, kad backup aplankas turėtų rašymo teises (644)
Komentarų nėra:
Rašyti komentarą