• 定时备份docker mysql


    1.新建脚本,添加脚本内容

    vi   mysql_backup.sh 
    

      

    #!/bin/bash
    # 设置mysql的登录用户名和密码(根据实际情况填写)
    mysql_user="root"
    mysql_password="123456"
    mysql_host="localhost"
    mysql_port="3306"
    mysql_charset="utf8mb4"
     
    # 备份文件存放地址(根据实际情况填写)
    backup_location=/home/mysql/backup
     
    # 是否删除过期数据
    expire_backup_delete="ON"
    expire_days=7
    backup_time=`date +%Y%m%d%H%M`
    backup_dir=$backup_location
    welcome_msg="Welcome to use MySQL backup tools!"
    # 备份指定数据库中数据(此处假设数据库是mysql_backup_test)
    docker exec -i mysql mysqldump -h$mysql_host -P$mysql_port -u$mysql_user -p$mysql_password -B myshop > $backup_dir/mysql_backup-$backup_time.sql
     
    # 删除过期数据
    if [ "$expire_backup_delete" == "ON" -a  "$backup_location" != "" ];then
            `find $backup_location/ -type f -mtime +$expire_days | xargs rm -rf`
            echo "Expired backup data delete complete!"
    fi
    

      

     2.新建定时任务

    #新建定时任务命令
    crontab -e
    #查看定时任务命令
    crontab -l
    #删除所有定时任务命令
    crontab -r
    

      

    26 9 * * * cd /home/mysql;./mysql_backup.sh >> log.txt 2>&1
    

      

    每天9:26执行定时任务 
  • 相关阅读:
    iOS单选和全选
    仿微信-ActionSheet
    NSArray 快速求和、平均值、最大值、最小值
    iOS学习资源集合
    iOS-Runtime字体适配
    仿网易新闻标题栏
    极光推送封装
    iOS导航栏自由缩放头像效果
    iOS判断字母、数字串
    Perl6多线程3: Promise start / in / await
  • 原文地址:https://www.cnblogs.com/jtlgb/p/13404715.html
Copyright © 2020-2023  润新知