• 数据库:ubantu下MySQL数据库备份方法


    1、编辑/etc/crontab文件设定定时任务,在制定时间执行backup_databases.sh

    vi /etc/crontab

    # /etc/crontab: system-wide crontab
    # Unlike any other crontab you don't have to run the `crontab'
    # command to install the new version when you edit this file
    # and files in /etc/cron.d. These files also have username fields,
    # that none of the other crontabs do.
    
    SHELL=/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    
    # m h dom mon dow user  command
    17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
    25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
    47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
    52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
    
    25 9 * * *  root sh /home/autotest/backup_databases.sh

    2、编写backup_databases.sh,内容如下:

    #!/bin/bash
    # Set the backup filename and directory
    DATE=`date +%Y%m%d` # e.g 20101025
    FILENAME="trunk_development_database_$DATE.sql";
    BACKUPDIR="/backup/";
    # Database Credentials
    DBUSER="root";
    DBPWD="123qwe^&*";
    DBNAME="trunk_development";
    # Change to the root directory
    cd /
    # Where is our gzip tool for compression?
    # The -f parameter will make sure that gzip will
    # overwrite existing files
    GZIP="/bin/gzip -f";
    # Delete old backups older than 3 days
    find /backup/trunk_development_*gz -mtime +3 -exec rm {} ;
    # execute the database dump
    mysqldump --user=$DBUSER --password=$DBPWD --add-drop-table --databases $DBNAME > $BACKUPDIR$FILENAME
    # compress the database backup$GZIP $BACKUPDIR$FILENAME

    3、手动创建目录/backup

  • 相关阅读:
    对Spring 框架 AOP(面向切面)的理解
    页面自动刷新
    页面通过ajax传值到后台,后台返回值展示在页面输入框
    java中怎么跳出两层for循环
    人的三种思维角度
    我理解的战争(程序员是需要有立场的)
    我所理解的JavaScript中的prototype与__proto__、constructor
    一个"失速"项目的总结
    TDD学习笔记
    Java SQL动态生成库
  • 原文地址:https://www.cnblogs.com/zs-note/p/4788120.html
Copyright © 2020-2023  润新知