• windows下mysql自动定时备份bat


    @echo off

    : basedata
    set ip=192.168.12.41
    set user=root
    set password=12456

    set databaseName=test

    set /a backupDays=7
    set mysqlBinPath=C:Program FilesMySQLMySQL Server 5.5in
    set mysqlBackupPath=D:mysql_back
    rem winxp/2003
    set logs=%mysqlBackupPath%logs.txt
    set day=%date:~7,2%
    set month=%date:~4,2%
    set /a year=%date:~10,4%
    rem win7/2008
    set day=%date:~8,2%
    set month=%date:~5,2%
    set /a year=%date:~0,4%

    if not exist %mysqlBackupPath% md %mysqlBackupPath%
    echo %year%-%month%-%day% >> %logs%

    set backupingFilePath=%mysqlBackupPath%\%databaseName%_%year%-%month%-%day%.sql
    cd /d %mysqlBinPath%

    echo backupdata >> %logs%
    set errorlevel=0
    echo errorlevel=%errorlevel%
    mysqldump -h%ip% -u%user% -p%password% --default-character-set=gbk --opt --extended-insert=false --triggers -R --hex-blob -x %databaseName%>%backupingFilePath%
    set /a myerrorlevel=%errorlevel%
    echo myerrorlevel=%myerrorlevel%
    if %myerrorlevel% leq 0 (
    if exist %backupingFilePath% (
    echo backupcomplete mysqlBackup_%year%-%month%-%day%.sql
    echo  backupcomplete mysqlBackup_%year%-%month%-%day%.sql >> %logs%
    ) else (
    echo backupfaile
    echo backupfaile >> %logs%
    pause
    exit
    )
    ) else (
    echo backupfail
    echo backupfail >> %logs%
    if exist %backupingFilePath% (
    del %backupingFilePath%
    )
    pause
    exit
    )
    rem delete backupDays's backup


    set /a day=1%day%-100-backupDays
    rem 
    if %day% lss 1 (
    set /a daysTemp=day
    call :daysOfLastMonth
    ) else set /a daysTemp=0
    set /a day+=daysTemp
    rem 
    if day lss 10 (set day=0%day%)
    set /a month=%month%
    if %month% lss 10 (set month=0%month%)

    set deleteBackupFilePath=%databaseName%%year%%month%%day%.sql
    echo mysqlBackup_%year%-%month%-%day%.sql
    echo mysqlBackup_%year%-%month%-%day%.sql >> %logs%
    if exist %mysqlBackupPath%\%deleteBackupFilePath% (
    del %mysqlBackupPath%\%deleteBackupFilePath%
     
    echo delcomplete >> %logs%
    ) else (

    echo the document isn't exist >> %logs%
    )
    echo -----------------------------------------------------end >> %logs%


    :daysOfLastMonth
    set /a month=%month%-1
    set /a mod1=%year%%%4
    set /a mod2=%year%%%100

    if %month% lss 1 (
    set month=12
    set year=%year%-1
    set day=31
    ) else (
    if %month% == 2 (
    set day=28
    if %mod1% == 0 (
    set day=29
    if mod2 == 0 (
    set day=28
    )
    )
    ) else (
    for %%a in (1 3 5 7 8 10 12) do (
    if %month% == %%a (
    set day=31
    goto :eof
    )
    )
    set day=30
    )
    )
    goto :eof 

     http://blog.csdn.net/chenzenan/article/details/8469034
  • 相关阅读:
    CSS中各种长度单位总结
    Android中实现双击(多击)事件
    android 文件保存到应用和sd卡中
    在Eclipse中搭建Android开发环境
    算法空间复杂度
    我的Android案例签到日历
    Android使用SDKManager下载SDK速度慢 容易丢包和异常的解决办法
    Android应用系列:仿MIUI的Toast动画效果实现
    Android学习笔记之数据的Sdcard存储方法及操作sdcard的工具类
    Android学习笔记之Menu的ShowAsAction属性的设置
  • 原文地址:https://www.cnblogs.com/wcLT/p/5337343.html
Copyright © 2020-2023  润新知