码迷,mamicode.com
首页 > Web开发 > 详细

Web网站维护的备份脚本

时间:2020-09-23 23:29:36      阅读:51      评论:0      收藏:0      [点我收藏+]

标签:man   database   help   spec   dir   备份   ack   网站   shel   

不得不说回到河南真是惨,正儿八经上班拿不到工资、还得去走劳动仲裁和打官司,只能靠接点小活儿挣个生活费了。

这是一个shell脚本,鄙人用来给在维护的web站点做文件备份使用。

cat backupFiles.sh
#!/bin/bash
################ README INFO #####################

Purpose: Backup files to a speciel folder

Made By: PomanTeng

E-mail: 1807479153@qq.com

WeChat: 1807479153

Version Identification Number:V0.00

Procedure Identification Number:20200920

##################################################

Declare User-Variable

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

  • BAK_DIR=/opt/WEB_backup/20200920
  • MYSQLDB=wordpress
  • MYSQLUSR=root
  • MYSQLPASS=12345678
  • ‘[‘ 0 -ne 0 ‘]‘
  • ‘[‘ ‘!‘ -d /opt/WEB_backup/20200920 ‘]‘
  • echo ‘/opt/WEB_backup/20200920 is exists...‘
    /opt/WEB_backup/20200920 is exists...
  • mysqldump -uroot -p12345678 wordpress
    backupFiles.sh: line 30: mysqldump: command not found
    ++ echo /opt/WEB_backup/20200920/wordpress
  • tar -czvf /opt/WEB_backup/20200920/wordpressWebProgram.tar.gz -C /home/wwwroot/
    tar: Cowardly refusing to create an empty archive
    Try tar --help‘ ortar --usage‘ for more information.
  • cp /usr/local/nginx/站点.conf /opt/WEB_backup/20200920/站点.conf
    cp: cannot stat ‘/usr/local/nginx/站点.conf’: No such file or directory
  • ‘[‘ -f /opt/WEB_backup/20200920/wordpress.sql ‘]‘
  • echo ‘Backup Database OK!‘
    Backup Database OK!
  • ‘[‘ -f /opt/WEB_backup/20200920/wordpressWebProgram.tar.gz ‘]‘
  • echo ‘Backup WebProgram failure!‘
    Backup WebProgram failure!
  • ‘[‘ -f /opt/WEB_backup/20200920/站点.conf ‘]‘
  • echo ‘Backup Vhost failure!‘
    Backup Vhost failure!
  • find /opt/WEB_backup/20200920 -type d -mtime +15 -exec rm -r ‘{}‘ ‘;‘
    [root@localhost Public]#

技术图片

Web网站维护的备份脚本

标签:man   database   help   spec   dir   备份   ack   网站   shel   

原文地址:https://blog.51cto.com/6286393/2536235

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!