zoukankan      html  css  js  c++  java
  • mysql备份脚本(基础版)

    #!/bin/bash
    #authors misery 2019
    #
    
    BAK_DIR=/home/web_code1/backup/mysql_backup/`date +%Y-%m-%d`
    MYSQL_CMD=/usr/bin/mysqldump
    MYSQL_USER=root
    MYSQL_PW=123456
    MYSQL_DB=webapp
    
    #判断用户是否正确
    if [ $UID -ne 0 ];then
        echo -e "33[1;31myou must be use root run '$0'33[0m"
        exit
    fi
    
    #判断备份目录是否存在
    if [ ! -d $BAK_DIR ];then
        mkdir -p $BAK_DIR
        echo -e "33[32m$BAK_DIR Create new directory Successfully33[0m"
    else
        echo -e "33[33mThis directory $BAK_DIR already exist33[0m"
    fi
    
    # mysqldump -uroot -proot salt > $BAK_DIR/salt.sql
    # 使用mysqldump工具执行备份命令
    if [ -f $BAK_DIR/$MYSQL_DB.sql ];then
        echo -e "33[33m$MYSQL_DB.sql Backup already exists,please check out.33[0m"
        exit
    else
        echo -e "33[32mBackup is running...33[0m"
        $MYSQL_CMD -u$MYSQL_USER -p$MYSQL_PW -d $MYSQL_DB > $BAK_DIR/$MYSQL_DB.sql
        if [ $? -eq 0 ];then
            echo -e "33[32mMySQL backup successfully.33[0m"
        else
            echo -e "33[33mmysql backup failed,please check33[0m"
        fi
    fi
    
    #加入定时任务:
    # 0 0 * * * /bin/bash /root/auto_backup_mysql.sh >> /var/log/backup_mysql.log 2>&1
  • 相关阅读:
    [SUCTF 2019]Pythonginx
    [极客大挑战 2019]BuyFlag
    [GXYCTF2019]Ping Ping Ping
    git 常用命令记录
    webpack4.X + react-router 路由跳转
    webpack4.X + react搭建
    windows 下 node 安装 react
    valueOf()、toString()
    isFinite()
    Javascript 闭包
  • 原文地址:https://www.cnblogs.com/bestOPS/p/11246206.html
Copyright © 2011-2022 走看看