标签:man database help spec dir 备份 ack 网站 shel
不得不说回到河南真是惨,正儿八经上班拿不到工资、还得去走劳动仲裁和打官司,只能靠接点小活儿挣个生活费了。这是一个shell脚本,鄙人用来给在维护的web站点做文件备份使用。
cat backupFiles.sh
#!/bin/bash
################ README INFO #####################
##################################################
BAK_DIR=/opt/WEB_backup/date +%Y%m%d
MYSQLDB=wordpress
MYSQLUSR=root
MYSQLPASS=12345678
if [ $UID -ne 0 ];then
echo "Must to be user root for exec shell."
exit
fi
if [ ! -d $BAK_DIR ];then
mkdir -p $BAK_DIR
echo "$BAK_DIR Create successfully!"
else
echo "$BAK_DIR is exists..."
fi
#备份数据库
mysqldump -u$MYSQLUSR -p$MYSQLPASS $MYSQLDB > "$BAK_DIR"/"$MYSQLDB".sql
#备份程序
tar -czvf echo "$BAK_DIR/$MYSQLDB"
WebProgram.tar.gz -C /home/wwwroot/
#备份站点配置文件
cp /usr/local/nginx/站点.conf "$BAK_DIR"/站点.conf
#检测备份是否成功
[ -f "$BAK_DIR"/"$MYSQLDB".sql ] && echo "Backup Database OK!" ||echo "Backup Database failure!"
[ -f "$BAK_DIR"/"$MYSQLDB"WebProgram.tar.gz ] && echo "Backup WebProgram OK!" ||echo "Backup WebProgram failure!"
[ -f "$BAK_DIR"/站点.conf ] && echo "Backup Vhost OK!" ||echo "Backup Vhost failure!"
#删除15天前的备份文件夹
find /opt/WEB_backup/* -type d -mtime +15 -exec rm -r {} \;
[root@localhost Public]#
[root@localhost Public]# sh -n backupFiles.sh
[root@localhost Public]# sh -x backupFiles.sh
++ date +%Y%m%d
tar --help‘ or
tar --usage‘ for more information.标签:man database help spec dir 备份 ack 网站 shel
原文地址:https://blog.51cto.com/6286393/2536235