自动备份脚本(Windows和Linux)

 Mysql自动备份脚本(Windows和Linux):

Windows环境下的备份脚本:

rem windows环境下Mysql数据库的自动备份脚本。
rem 可以将本批处理设成windows任务计划下自动执行
 
@echo off
@echo ================================================
@echo  windows环境下Mysql数据库的自动备份脚本
@echo ================================================
rem 根据情况需要配置
rem 备份存放目录
set BACKUP_DIR="E:\Backup\mysql"
rem mysql数据库目录
set MYSQL_HOME="D:\Server\MySQL Server 5.1"
rem 用来备份的mysql帐号
set BACKUP_USER=backup
rem 帐号密码
set BACKUP_PASSWORD=033969965
 
rem 进行备份
rem 备份的数据库
set BACKUP_DB=ucenter
for /f "tokens=1,2" %%a in ('date/t') do set TODAY=%%a
set BACK_NAME=%BACKUP_DB%_%date:~0,4%%date:~5,2%%date:~8,2%_%time:~3,2%%time:~6,2%%time:~9,2%
%MYSQL_HOME%\bin\mysqldump.exe -u%BACKUP_USER% -p%BACKUP_PASSWORD% %BACKUP_DB% > %BACKUP_DIR%\%BACKUP_DB%.sql
rem 将备份进行存档
cd %BACKUP_DIR%
copy %BACKUP_DB%.sql zip\%BACK_NAME%.sql


Linux环境下的备份脚本:

#!/bin/sh
 
#根据情况需要配置
#备份存放目录
BACKUP_DIR=/opt/backup/mysql
#mysql数据库目录
MYSQL_HOME=/opt/mysql
#用来备份的mysql帐号
BACKUP_USER=backup
#帐号密码
BACKUP_PASSWORD=033969965
 
#进行备份
#备份的数据库
BACKUP_DB=jacken
$MYSQL_HOME/bin/mysqldump -u$BACKUP_USER -p$BACKUP_PASSWORD $BACKUP_DB > $BACKUP_DIR/$BACKUP_DB.sql
#将备份进行压缩存档
cd $BACKUP_DIR
tar -zcvf  ./zip/$BACKUP_DB-`date +%y%m%d%H%M`.tar.gz $BACKUP_DB.sql


 

Oracle自动备份脚本(Windows和Linux):

Windows环境下的备份脚本:

rem windows环境下Oracle数据库的自动备份脚本。
rem 可以将本批处理设成windows任务计划下自动执行。
 
@echo off
@echo ================================================
@echo  windows环境下Oracle数据库的自动备份脚本
@echo ================================================
 
rem 以下变量需要根据实际情况配置
rem 备份存放的目录
set BACKUP_DIR=D:\DataBaseBackUp
 
rem 配置
rem 备份的数据库
set USER=data_center
rem 数据库密码
set PASSWORD=123456
rem 备份
for /f "tokens=1,2" %%a in ('date/t') do set TODAY=%%a
set BACK_NAME=%USER%_%TODAY%(%time:~0,2%时%time:~3,2%分)
set BACK_FULL_NAME=%BACKUP_DIR%\%BACK_NAME%
exp %USER%/%PASSWORD%@orcl owner=%USER% file="%BACK_FULL_NAME%.dmp" log="%BACK_FULL_NAME%.log"


Linux环境下的备份脚本:

#!/bin/sh
#根据情况需要配置
#数据库备份存放目录
BACKUP_DIR=/opt/backup/oracle
#进行备份
#备份数据库名
BACKUP_USER=exam
#数据库密码
BACKUP_PASSWORD=123456
su - oracle -c "exp $BACKUP_USER/$BACKUP_PASSWORD owner=$BACKUP_USER file=$BACKUP_DIR/$BACKUP_USER.dmp log=$BACKUP_DIR/$BACKUP_USER.log"
#将备份进行压缩存档
cd $BACKUP_DIR
tar -zcvf  ./zip/$BACKUP_USER-`date +%y%m%d%H%M`.tar.gz  $BACKUP_USER.dmp $BACKUP_USER.log


 

你可能感兴趣的:(Linux)