由于当前的网站没有什么流量,数据量也不大,所以网站采用全备的方法,网页和数据库备份脚本如下:
网页备份:
- [python] view plaincopyprint?
- #!/bin/bash
- #######################
- #
- # htdocs_backup
- #
- #######################
- date=`date +%Y%m%d_%H%M`
- htdocs_backdir="/root/backup/htdocs_backup"
- echo "Htdocs is now backuping..."
- tar cf $htdocs_backdir/htdocs_$date.tar /data/home/htdocs >/dev/null 2>&1
- if [ $? -eq 0 ];then
- echo "htdocs backup ok!"
- else
- echo "htdocs backup failed!"
- fi
- find $htdocs_backdir -mtime +7 -exec rm -rf '{} \;'
数据库备份:
- [python] view plaincopyprint?
- #!/bin/bash
- ########################
- #
- # mysql_all dump
- #
- ########################
- date=`date +%Y%m%d_%H%M`
- mysql_backdir="/root/backup/mysql_backup"
- echo "Now the mysql_dump is starting..."
- mysqldump --all-databases --skip-opt -u root -pxxxxx > $mysql_backdir/all_mysql_$date.sql 2>/root/backup/log_error/mysql-error_log
- if [ $? -eq 0 ];then
- echo "Mysql_all dump is ok!"
- else
- echo "Mysql_all dump is failed!"
- fi
- find $mysql_backdir -mtime +7 -exec rm -rf '{} \;'
其中脚本中之所以在find中'{} \;'使用单引号是出现如下错误:
# find ./* -mtime +7 -exec rm -rf {} \;
/usr/lib/.khostd/find: 遗漏“-exec”的参数
需要加上单引号才可以生效
转载于:https://blog.51cto.com/kumu1988/1085769