一键备份MySQL数据库与nginx虚拟主机添加

一键备份MySQL数据库与nginx虚拟主机添加

目录:
1、一键备份MYSQL数据库脚本

  • 支持单个任意数据库的备份
  • 支持多个数据库同时备份
  • 支持所有数据库同时备份

2、一键Nginx虚拟主机添加脚本

  • 支持单个虚拟主机添加
  • 持任意域名虚拟主机添加;

1、一键备份MySQL数据库

前提MySQL密码:mysqladmin -u root password "abc-123"
#!/bin/bash
#mysql_db_backup_v1.sh
#################
MYSQL_NAME=$*
MYSQL_USER=root
MYSQL_PW=abc-123
MYSQL_DIR=/data/mysql/`date +%F`
if (( $# < 1 ));then
        echo "请在脚本后输入所需要备份的数据库名"
        exit 1
fi

if [[ $1 == all ]];then
        /usr/bin/mysqldump -u$MYSQL_USER -p$MYSQL_PW --all-databases > $MYSQL_DIR/mysql_$*.sql
        echo -e "\033[32m所有数据库已备份完毕\033[0m"
        exit 0
fi

for i in $*
do
        if [[ ! -d ${MYSQL_DIR} ]];then
                mkdir -p ${MYSQL_DIR}
        fi
        /usr/bin/mysqldump -u$MYSQL_USER -p$MYSQL_PW -d $i > $MYSQL_DIR/mysql_${i}.sql
        echo -e "\033[32m数据库${i}已备份完成\033[0m"
done

2、nginx虚拟主机添加

#!/bin/bash
#nginx_vhost_add_v4.sh
#yum_nginx版
#2021/03/03 16:26
######################
NGINX_BASE="/etc/nginx/conf.d"
NGINX_WEB="/usr/share/nginx/html"
NGINX_UP="/usr/sbin/nginx"
NGINX_YUM="yum -y install nginx-1.18.0"

if (( $# < 1 ));then
        echo "在脚本后追加所需创建的虚拟主机的名称"
        exit 1
fi

if [ ! -x $NGINX_UP ];then
        echo -e "\033[32mnginx未安装,正在使用yum方式安装nginx\033[0m"
        $NGINX_YUM > /dev/null
        `systemctl start nginx` && echo -e "\033[32m已安装并成功启动nginx服务\033[0m"
fi

for i in $*
do
        if [ ! -f ${NGINX_BASE}/${i}.conf ];then
                touch ${NGINX_BASE}/${1}.conf
        fi

cat > ${NGINX_BASE}/${i}.conf << EOF
server {
        listen 80;
        server_name $i;
        location / {
                index index.html;
                root /usr/share/nginx/html/$i;
        }
}
EOF
        if [ ! -d $NGINX_WEB/$i ];then
                mkdir -p /${NGINX_WEB}/${i}
                                echo -e "\033[32m 创建${i}发布目录\033[0m"
        fi
cat > /$NGINX_WEB/$i/index.html << EOF
<html>
        <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        </head>
        <body>
                <h2> $i测试页面 </h2>
        </body>
</html>
EOF
echo -e "\033[32m 虚拟主机${i}创建成功 \033[0m"
done
systemctl reload nginx
netstat -nptl | grep nginx
#PS:前提关闭防火墙
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值