123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #!/bin/bash
- SITE_CODE=$1
- FROM_DIR="/usr/local/wwwroot/"
- DIR_TO_CHECK=$FROM_DIR$SITE_CODE
- TARGET_DIR="/opt/adweb3/wp_bak/"
- RDS_HOST='127.0.0.1'
- RDS_ADMIN='root'
- RDS_PWD='Initial0_123'
- if [ -d "$DIR_TO_CHECK" ]; then
-
-
-
-
- cd $FROM_DIR
- echo "开始打包项目到$TARGET_DIR$SITE_CODE.tar.gz"
- sudo tar -czf $TARGET_DIR$SITE_CODE.tar.gz $SITE_CODE
-
- if [ $? -eq 0 ]; then
- echo "目标项目已经成功打包到$TARGET_DIR$SITE_CODE.tar.gz"
- sudo rm -rf $DIR_TO_CHECK
- if [ $? -eq 0 ]; then
- echo "打包后删除该项目目录$SITE_CODE"
- fi
- else
- echo "Failed to move the directory."
- fi
-
-
-
- mysqldump --user=$RDS_ADMIN --password=$RDS_PWD --host=localhost --port=3306 --no-create-db --default-character-set=utf8 $SITE_CODE > $TARGET_DIR$SITE_CODE.sql
-
- if [ $? -eq 0 ]; then
- echo "Database $SITE_CODE has been backup."
- else
- echo "Failed to backup database $SITE_CODE."
- fi
-
-
-
- mysql -u $RDS_ADMIN -p$RDS_PWD -e "DROP DATABASE $SITE_CODE;"
-
- if [ $? -eq 0 ]; then
- echo "Database $SITE_CODE has been deleted."
- else
- echo "Failed to delete database $SITE_CODE."
- fi
-
- sudo rm -f /usr/local/openresty/nginx/vhost/$SITE_CODE.conf
-
- sudo rm -f /usr/local/openresty/nginx/logs/$SITE_CODE.error.log
- sudo rm -f /usr/local/openresty/nginx/logs/$SITE_CODE.access.log
- echo "reload nginx config"
- /usr/local/openresty/nginx/sbin/nginx -s reload
- echo "reload nginx config done!"
- else
-
- sudo rm -f /usr/local/openresty/nginx/vhost/$SITE_CODE.conf
-
- sudo rm -f /usr/local/openresty/nginx/logs/$SITE_CODE.error.log
- sudo rm -f /usr/local/openresty/nginx/logs/$SITE_CODE.access.log
- echo "remove nginx $SITE_CODE config and log file"
-
- echo "The specified directory does not exist."
- fi
|