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
  • 相关阅读:
    004 cat、head、tail、vim、cp、mv、rm
    003 系统的结构目录、pwd、cd、ls、tree、mkdir、touch
    shell编程
    多线程
    接口(适配器)
    常用方法
    爬虫要具备的准则:
    知识点扫盲篇
    记录_20190628
    记录_20190626
  • 原文地址:https://www.cnblogs.com/bestOPS/p/11246206.html
Copyright © 2011-2022 走看看