Web網站維護的備份腳本

不得不說回到河南真是慘,正兒八經上班拿不到工資、還得去走勞動仲裁和打官司,只能靠接點小活兒掙個生活費了。mysql

這是一個shell腳本,鄙人用來給在維護的web站點作文件備份使用。nginx

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

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

##################################################sql

Declare User-Variable

BAK_DIR=/opt/WEB_backup/date +%Y%m%d
MYSQLDB=wordpress
MYSQLUSR=root
MYSQLPASS=12345678shell

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..."
fibash

#備份數據庫
mysqldump -u$MYSQLUSR -p$MYSQLPASS $MYSQLDB > "$BAK_DIR"/"$MYSQLDB".sqlide

#備份程序
tar -czvf echo "$BAK_DIR/$MYSQLDB"WebProgram.tar.gz -C /home/wwwroot/wordpress

#備份站點配置文件
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網站維護的備份腳本

相關文章
相關標籤/搜索