Linux 备份文件和数据库发送到邮箱
今天一个误操作把一个月的文件备份和数据库备份删掉了
做了一个用sendmail发送到邮箱的备份脚本:
#!/bin/bash # X , sendmail hoodbc20117 ### Setting path ### BACKPATH="/data0/mysql_bak" DATE=`/bin/date "+%Y-%m-%d-%H-%M-%S"` zip -rq $BACKPATH/erp_$DATE.zip /data/htdocs/www/erp/ echo "erp all backup" | mutt -a $BACKPATH/erp_$DATE.zip -s "erp all backup" [email protected] find $BACKPATH -ctime +30 -name *.zip -delete
顺便把数据库备份的脚本也记录下来:
#!/bin/bash # hoodbc20117 ### database setting ### USER='root' PASSWORD='' HOST="127.0.0.1" DATABASES=(erp) ### Setting path ### MYSQLDUMP=/usr/local/webserver/mysql/bin/mysqldump BACKPATH="/data0/mysql_bak" DATE=`/bin/date "+%Y-%m-%d-%H-%M-%S"` for DATABASE in ${DATABASES[*]} do FILENAME="$DATABASE-$DATE" $MYSQLDUMP --add-drop-table --user $USER --password=$PASSWORD $DATABASE --lock-all-tables>> "$BACKPATH/$FILENAME.sql" done #tar zcf -r $BACKPATH/erp_$DATE.tar.gz ~/data/htdocs/www/erp #zip -rq $BACKPATH/erp_$DATE.zip /data/htdocs/www/erp/ zip -rq $BACKPATH/$FILENAME.zip $BACKPATH/$FILENAME.sql echo "erp db backup" | mutt -a $BACKPATH/$FILENAME.zip -s "erp db backup" [email protected] find $BACKPATH -ctime +30 -name *.sql -delete
记得加上--lock-all-tables的参数,这样在导出sql文件的时候会锁定表,当然也可以直接把数据库文件打包。最后加到crontab里定时运行脚本。
相关推荐
wenjieyatou 2020-01-14
hck0ne 2020-01-14
bluetears 2020-01-12
bleach00 2020-11-10
林德强之原创 2020-08-13
PlumRain 2020-08-03
bob于 2020-07-26
dataminer 2020-06-25
neverstopforcode 2020-06-18
zxznsjdsj 2020-06-16
langyue 2020-06-13
huangyx 2020-06-11
鲁氏汤包王 2020-06-11
LWLWLiang 2020-05-28
wkwanglei 2020-05-26
Coohx 2020-04-13
thunderstorm 2020-05-09
Andrea0 2020-05-04
数据库工具开发 2020-04-25