zoukankan      html  css  js  c++  java
  • shell 备份数据库,并移动到备份数据库

    
    # 配置mysql备份
    00 03 * * * sh /home/cron/back_mysql_db.sh >> /tmp/back_mysql_db.log 2>&1
    30 03 * * * /home/cron/scp_back_to_test.sh /home/wwwroot/default/mysqlbackups/ >> /tmp/scp_back_to_test.log 2>&1
    
    
    -----------------------------------------------------------执行备份数据库脚本-------------------------------------------------------------
    
    
    [root@c118c178c255c134 cron]# cat back_mysql_db.sh 
    #!/bin/bash
    
    # 没有则创建
    if [ ! -d "/home/wwwroot/default/mysqlbackups" ];then
            mkdir -p "/home/wwwroot/default/mysqlbackups"
    fi
    
    # 备份数据库
    mysqldump -uroot -p**** daping > /home/wwwroot/default/mysqlbackups/daping_$(date + %Y%m%d%H%M%S).sql
    
    # 只保留5天的数据库
    find /home/wwwroot/default/mysqlbackups/ -type f -ctime +3 -exec rm -rf {} ;
    
    
    ----------------------------------------------移动备份数据库到备份数据库-----------------------------------------------------------
    crontab -e
    30 3 * * * sh /home/sh/clear_old_mysql_db.sh >> /tmp/clear_old_mysql_db.log 2 >&1
    
    
    [root@c118c178c255c134 cron]# cat scp_back_to_test.sh 
    #!/usr/bin/expect
    
    set user root
    set password ********
    set dir /home/wwwroot/default/
    set ip 218.93.***.**
    set files [lrange $argv 0 0]
    
    spawn scp -r ${files} ${user}@${ip}:${dir}
    expect {  
        "*yes/no*" { send "yes
    "; exp_continue}
        "*password:*" { send "$password
    "; exp_continue }
    }
    
    
    interact
    
    
    
    -------------------------------备份所在服务器,定期删除多余备份数据库脚本!!!------------------------------
    30 3 * * * sh /home/sh/clear_old_mysql_db.sh >> /tmp/clear_old_mysql_db.log 2 >&1
    
    
    [root@caomall mysqlbackups]# cat /home/sh/clear_old_mysql_db.sh 
    #!/bin/bash
    
    # 清理超过3天的数据
    find  /home/wwwroot/default/mysqlbackups/  -type f -ctime +3 -exec rm -rf {} ;
    echo "清理成功";
    
  • 相关阅读:
    some tips
    ORA00847: MEMORY_TARGET/MEMORY_MAX_TARGET and LOCK_SGA cannot be set together
    Chapter 01Overview of Oracle 9i Database Perfomrmance Tuning
    Chapter 02Diagnostic and Tuning Tools
    变量与常用符号
    Chapter 18Tuning the Operating System
    标准输入输出
    Trace files
    DBADeveloped Tools
    Chapter 03Database Configuration and IO Issues
  • 原文地址:https://www.cnblogs.com/pansidong/p/12957166.html
Copyright © 2011-2022 走看看