• 技术文章 >数据库 >mysql教程

    A Simple MySQL Daily Backup Script_MySQL

    2016-06-01 13:07:38原创767

    06.23.2014|69 views|

    Related MicroZone Resources

    Clustrix Whitepapers

    INFOGRAPHIC: The Future of the Database

    What We Offer: Clustrix Features

    Proven in Production: Clustrix Case Studies

    Like this piece? Share it with your friends:

    |More

    Using the MySQL export script I've showed from thelast post(assuming you saved it in a file named "$HOME/database-export.sh"), you may now perform a daily backup with your crontab service like this.

    #file: mysql-backups.shDIR=`dirname $0`echo "Backup DB with export script."$DIR/database-export.shecho "Moving exported files into backup dir."DB_BAK_DIR=$HOME/mysql-backups/`date +%a`echo "Removing old file (if exists) and saving new backup into $DB_BAK_DIR"if [[ -e $DB_BAK_DIR ]]; thenrm -fv $DB_BAK_DIR/*elsemkdir -p $DB_BAK_DIRficp -v $DIR/*.sql $DB_BAK_DIR

    This script should create a daily folder under your home directory, for example like "$HOME/mysql-backups/Mon", "Tue", "Wed" etc. It should save up to 7 days in a week if you run this with a daily cron job.

    # crontab -e@daily $HOME/mysql-backups.sh > /dev/null 2>&1

    This is not the most robust way of backing up your DB, but it's a simple solution if you just want something quick up and running without worry too much.

    Published at DZone with permission ofZemian Deng, author and DZone MVB. (source)

    (Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

    Tags:
    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:
    上一篇:MySql引擎 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • MySQL学习之聊聊查询语句执行流程• hive和mysql的区别有哪些• mysql数据库的超级管理员名称是什么• mysql怎么连接数据库• mysql事务隔离级别有哪些
    1/1

    PHP中文网