oracle,mysql数据库自动备份脚本

oracle,mysql数据库自动备份脚本

1.oracle数据库备份

直接上脚本吧:

@echo 开始备份…. 
set projectname=oracleceshi
set basepath=C:\oracle\backup\

set instanse=ORCL
set username=ILANNI
set password=123456

set datapath=%basepath%%projectname%\data\
set logpath=%basepath%%projectname%\log\

set NO=%Date:~0,4%%Date:~5,2%%Date:~8,2%
set t=%Time%
if "%t:~0,1%" ==" " (
set t=0%t:~1%
)
set NO=%Date:~0,4%%Date:~5,2%%Date:~8,2%%t:~0,2%%t:~3,2%%t:~6,2%

mkdir "%datapath%"
mkdir "%logpath%"

set datafilename=%datapath%\%projectname%_%NO%
set logfilename=%logpath%%projectname%_%NO%

exp %username%/%password%@%instanse% file=%datafilename%.dmp owner=%username% log=%logfilename%.log

@echo 备份完毕!

@echo 执行sql…. 
@echo off
echo OK! 

新建xxx.bat文件,将以上代码粘贴进去,运行即可

稍微说明一下:
projectname  用来配置项目名
projectname  是生成的备份文件基础目录
instanse  数据库的实例名
username  数据库用户名
password  数据库密码

运行结果如下图所示:



2.mysql数据库备份

直接上代码:

@echo off

C:

cd C:\Program Files\MySQL\MySQL Server 5.6\bin

set NO=%Date:~0,4%%Date:~5,2%%Date:~8,2%

set t=%Time%

if "%t:~0,1%" ==" " (

set t=0%t:~1%

)

set NO=%Date:~0,4%%Date:~5,2%%Date:~8,2%%t:~0,2%%t:~3,2%%t:~6,2%

set filename=ceshinm_%NO%.sql     

mysqldump.exe -uroot -p123456 ceshinm> D:\数据库自动备份\ceshinm\%filename%

同oracle,修改写一下代码参数,将代码粘贴进xxx.bat文件,运行即可

如果想定时备份,直接打开windows的任务计划程序,新建 基本任务,将批处理文件添加进去,选好定时时间即可。




你可能感兴趣的:(oracle,数据库,mysql,备份,脚本)