资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

windows和linux环境自动备份脚本

@echo off   
echo ================================================   
echo  Windows环境下Oracle数据库的自动备份脚本  
echo  1. 使用当前日期命名备份文件。  
echo  2. 自动删除7天前的备份。  
echo ================================================  
::以“YYYYMMDD”格式取出当前时间。  
set BACKUPDATE=%date:~0,4%%date:~5,2%%date:~8,2%


::修改字符集。
set NLS_LANG=SIMPLIFIED CHINESE_CHINA.AL32UTF8


::设置用户名、密码和要备份的数据库。  
set USER=system
set PASSWORD=oracle
set DATABASE=ORCL


::创建备份目录。  
if not exist "D:\ORA_BAKUP\data"       mkdir D:\ORA_BAKUP\data
if not exist "D:\ORA_BAKUP\log"        mkdir D:\ORA_BAKUP\log
set DATADIR=D:\ORA_BAKUP\data
set LOGDIR=D:\ORA_BAKUP\log


exp %USER%/%PASSWORD%@ORCL  full=y direct=y recordlength=65535 file=%DATADIR%\exp_%DATABASE%_%BACKUPDATE%.dmp log=%LOGDIR%\exp_%DATABASE%_%BACKUPDATE%.log


::恢复语句
::imp username/passwd@TNS FROMUSER=** TOUSER=** FILE=** LOG=** BUFFER=20480000


::删除7天前的备份。  
forfiles /p "%DATADIR%" /s /m *.* /d -7 /c "cmd /c del @path"  
forfiles /p "%LOGDIR%" /s /m *.* /d -7 /c "cmd /c del @path"  
exit 


——————Windows日期表示方法——————————————————
echo %Date:~0,10%.rar   
2016/08/08.rar   (注:0,10代指10位)
(所以20160808表示为:)
echo %Date:~0,4%%Date:~5,2%%Date:~8,2%.rar  
20160808.rar
————————————————————————————————————————————
#########################
#Linux备份脚本
#########################
———————————脚本1 datapump—————————————————
集团业务备份脚本
############################################
#  Backup & Restore Script Using DataPump  #
############################################
export ORACLE_SID=xmtkfpr1
export ORACLE_BASE=/oracle/app/oracle
export ORACLE_HOME=/oracle/app/oracle/product/11.2.0.4/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
current_time=`date '+%Y%m%d'`

##############################
# 1.Backup Script
##############################

expdp userid=jt_wsq/wsq_2016!!! directory=dmp_bak_dir filesize=10G dumpfile=expdp_db_jt_wsq_%U.dmp logfile=expdp_db_jt_wsq_$current_time.log cluster=n parallel=2

##############################
# 2.Recover Script
##############################
#cd /expdata/dmp_bak
#tar -xzvf expdp_db_jt_wsq_$current_time.tar.gz 
#impdp userid=jt_wsq/wsq_2016!!! directory=dmp_bak_dir dumpfile=expdp_db_jt_wsq_%U.dmp logfile=impdp_db_jt_wsq.log parallel=2

##############################
# 3.Comress the Backup
##############################

cd /expdata/dmp_bak/
tar -zcvf  expdp_db_jt_wsq_$current_time.tar.gz expdp_db_jt_wsq_*.dmp --remove-files
find ./ -mtime +20 -name "expdp_db_jt_wsq*" -exec rm -rf {} \;
———————————脚本2 exp/imp————————————————————————————————————————
#Backup for oradb(16.7,16.12)  and SOHUDB(208)
#


echo ============================================
echo Begin Backup Time:`date`
echo ============================================
echo


source ~/.bash_profile
export DATE=`date +'%Y%m%d'`
export NLS_LANG=‘SIMPLIFIED CHINESE_CHINA.AL32UTF8'


#____1.Backup for oradb
cd /home/oracle/backup/oradb
exp bj_dx_immcc/bj_dx_immcc_123@ORADB  recordlength=65535 direct=y file=exp_bj_dx_immcc_$DATE.dmp log=exp_bj_dx_immcc_$DATE.log;
exp bj_dx_immcc_report/bj_dx_immcc_report_123@ORADB   recordlength=65535 direct=y file=exp_bj_dx_immcc_report_$DATE.dmp log=exp_bj_dx_immcc_report_$DATE.log;
exp bj_dx_yyjr/bj_dx_yyjr_123@ORADB   recordlength=65535 direct=y file=exp_bj_dx_yyjr_$DATE.dmp log=exp_bj_dx_yyjr_$DATE.log;




#____2.Backup for SOHODB
cd /home/oracle/backup/SOHODB
exp bj_soho_data/bj_soho_data_123@SOHUDB recordlength=65535 direct=y file=exp_bj_soho_data_$DATE.dmp log=exp_bj_soho_data_$DATE.log;




#____3.Remove Backup 3 Days ago
find /home/oracle/backup/oradb/ -mtime +3 -exec rm -rf {} \;
find /home/oracle/backup/SOHODB/ -mtime +3 -exec rm -rf {} \;


#____4.Recover Script
#imp username/passwd@TNS FROMUSER=** TOUSER=** FILE=** LOG=** BUFFER=20480000


echo
echo ============================================
echo End Backup Time:`date`
echo ============================================


=========================================================
rem 主目录
set backup_home=D:\database\dump
set NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
set current_date0=%date:~0,4%%date:~5,2%%date:~8,2%
mkdir %backup_home%\%current_date0%
rem 清理两天前的备份和日志
forfiles /p "%backup_home%" /s /m 20* /d -2 /c "cmd /c rd /s /q @path"  
forfiles /p "%backup_home%\log" /s /m *.log /d -7 /c "cmd /c del @path"  
/*
set YE=%date:~0,4%
set MO=%date:~5,2%
set DA=%date:~8,2%
set DG=2
set/a vY1=%YE% %% 400
set/a vY2=%YE% %% 4
set/a vY3=%YE% %% 100
if %vY1%==0 (set var=true) else (if %vY2%==0 (if %vY3%==0 (set var=false) else (set var=true)) else (set var=false))
set LY=%YE%
set LM=%MO%
if %MO:~0,1%==0 (set MO=%MO:~1,1%)
if %DA:~0,1%==0 (set DA=%DA:~1,1%)
if %DA% GTR %DG% (set/a LD=%DA%-%DG%) else (
if %MO%==1 (set/a LY=%YE%-1) & (set/a LM=12) & (set/a LD=31+%DA%-%DG%) else (
set/a LM=%MO%-1
if %MO%==3 (if %var%==false (set/a LD=28+%DA%-%DG%) else (set/a LD=29+%DA%-%DG%))
for %%a in (2 4 6 8 9 11) do (if "%MO%"=="%%a" (set/a LD=31+%DA%-%DG%))
for %%b in (5 7 10 12) do (if "%MO%"=="%%b" (set/a LD=30+%DA%-%DG%))))
if %LM% LSS 10 set LM=0%LM:~-1%
if %LD% LSS 10 set LD=0%LD:~-3%
set current_date1=%LY%%LM%%LD%
 
rd /s /q  %backup_home%\%current_date1%
*/
rem 备份当前数据库
call exp userid='system/Oracle114#@hbbst' log=%backup_home%\log\backup_db_hbbst_%current_date0%.log parfile=%backup_home%\backup_db_hbbst.par
mv /y %backup_home%\*.dmp %backup_home%\%current_date0%\




===========
owner=bdp
recordlength=32768
buffer=20000000
statistics=none
compress=n
filesize=10g
file=(
D:\database\dump\backup_db_hbbst_001.dmp,
D:\database\dump\backup_db_hbbst_002.dmp,
D:\database\dump\backup_db_hbbst_003.dmp,
D:\database\dump\backup_db_hbbst_004.dmp,
D:\database\dump\backup_db_hbbst_005.dmp,
D:\database\dump\backup_db_hbbst_006.dmp,
D:\database\dump\backup_db_hbbst_007.dmp,
D:\database\dump\backup_db_hbbst_008.dmp,
D:\database\dump\backup_db_hbbst_009.dmp,
D:\database\dump\backup_db_hbbst_010.dmp,
D:\database\dump\backup_db_hbbst_011.dmp,
D:\database\dump\backup_db_hbbst_012.dmp,
D:\database\dump\backup_db_hbbst_013.dmp,
D:\database\dump\backup_db_hbbst_014.dmp,
D:\database\dump\backup_db_hbbst_015.dmp,
D:\database\dump\backup_db_hbbst_016.dmp,
D:\database\dump\backup_db_hbbst_017.dmp,
D:\database\dump\backup_db_hbbst_018.dmp,
D:\database\dump\backup_db_hbbst_019.dmp,
D:\database\dump\backup_db_hbbst_020.dmp,
D:\database\dump\backup_db_hbbst_021.dmp,
D:\database\dump\backup_db_hbbst_022.dmp,
D:\database\dump\backup_db_hbbst_023.dmp,
D:\database\dump\backup_db_hbbst_024.dmp,
D:\database\dump\backup_db_hbbst_025.dmp,
D:\database\dump\backup_db_hbbst_026.dmp,
D:\database\dump\backup_db_hbbst_027.dmp,
D:\database\dump\backup_db_hbbst_028.dmp,
D:\database\dump\backup_db_hbbst_029.dmp,
D:\database\dump\backup_db_hbbst_030.dmp,
D:\database\dump\backup_db_hbbst_031.dmp,
D:\database\dump\backup_db_hbbst_032.dmp,
D:\database\dump\backup_db_hbbst_033.dmp,
D:\database\dump\backup_db_hbbst_034.dmp,
D:\database\dump\backup_db_hbbst_035.dmp,
D:\database\dump\backup_db_hbbst_036.dmp,
D:\database\dump\backup_db_hbbst_037.dmp,
D:\database\dump\backup_db_hbbst_038.dmp,
D:\database\dump\backup_db_hbbst_039.dmp,
D:\database\dump\backup_db_hbbst_040.dmp,
D:\database\dump\backup_db_hbbst_041.dmp,
D:\database\dump\backup_db_hbbst_042.dmp,
D:\database\dump\backup_db_hbbst_043.dmp,
D:\database\dump\backup_db_hbbst_044.dmp,
D:\database\dump\backup_db_hbbst_045.dmp,
D:\database\dump\backup_db_hbbst_046.dmp,
D:\database\dump\backup_db_hbbst_047.dmp,
D:\database\dump\backup_db_hbbst_048.dmp,
D:\database\dump\backup_db_hbbst_049.dmp,
D:\database\dump\backup_db_hbbst_050.dmp,
D:\database\dump\backup_db_hbbst_051.dmp,
D:\database\dump\backup_db_hbbst_052.dmp,
D:\database\dump\backup_db_hbbst_053.dmp,
D:\database\dump\backup_db_hbbst_054.dmp,
D:\database\dump\backup_db_hbbst_055.dmp,
D:\database\dump\backup_db_hbbst_056.dmp,
D:\database\dump\backup_db_hbbst_057.dmp,
D:\database\dump\backup_db_hbbst_058.dmp,
D:\database\dump\backup_db_hbbst_059.dmp,
D:\database\dump\backup_db_hbbst_060.dmp,
D:\database\dump\backup_db_hbbst_061.dmp,
D:\database\dump\backup_db_hbbst_062.dmp,
D:\database\dump\backup_db_hbbst_063.dmp,
D:\database\dump\backup_db_hbbst_064.dmp,
D:\database\dump\backup_db_hbbst_065.dmp,
D:\database\dump\backup_db_hbbst_066.dmp,
D:\database\dump\backup_db_hbbst_067.dmp,
D:\database\dump\backup_db_hbbst_068.dmp,
D:\database\dump\backup_db_hbbst_069.dmp,
D:\database\dump\backup_db_hbbst_070.dmp,
D:\database\dump\backup_db_hbbst_071.dmp,
D:\database\dump\backup_db_hbbst_072.dmp,
D:\database\dump\backup_db_hbbst_073.dmp,
D:\database\dump\backup_db_hbbst_074.dmp,
D:\database\dump\backup_db_hbbst_075.dmp,
D:\database\dump\backup_db_hbbst_076.dmp,
D:\database\dump\backup_db_hbbst_077.dmp,
D:\database\dump\backup_db_hbbst_078.dmp,
D:\database\dump\backup_db_hbbst_079.dmp,
D:\database\dump\backup_db_hbbst_080.dmp,
D:\database\dump\backup_db_hbbst_081.dmp,
D:\database\dump\backup_db_hbbst_082.dmp,
D:\database\dump\backup_db_hbbst_083.dmp,
D:\database\dump\backup_db_hbbst_084.dmp,
D:\database\dump\backup_db_hbbst_085.dmp,
D:\database\dump\backup_db_hbbst_086.dmp,
D:\database\dump\backup_db_hbbst_087.dmp,
D:\database\dump\backup_db_hbbst_088.dmp,
D:\database\dump\backup_db_hbbst_089.dmp,
D:\database\dump\backup_db_hbbst_090.dmp,
D:\database\dump\backup_db_hbbst_091.dmp,
D:\database\dump\backup_db_hbbst_092.dmp,
D:\database\dump\backup_db_hbbst_093.dmp,
D:\database\dump\backup_db_hbbst_094.dmp,
D:\database\dump\backup_db_hbbst_095.dmp,
D:\database\dump\backup_db_hbbst_096.dmp,
D:\database\dump\backup_db_hbbst_097.dmp,
D:\database\dump\backup_db_hbbst_098.dmp,
D:\database\dump\backup_db_hbbst_099.dmp,
D:\database\dump\backup_db_hbbst_100.dmp
)
================================
backup_db_zxin.sh


ORACLE_BASE=/oracle/app/oracle;export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db;export ORACLE_HOME
ORACLE_SID=zxin;export ORACLE_SID
export NLS_LANG=American_America.ZHS16GBK
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
export AIXTHREAD_SCOPE=S
export LANG=C
TEMP=/tmp; export TEMP 
TMPDIR=/tmp; export TMPDIR
umask 022
PATH=$PATH:$ORACLE_HOME/bin:/usr/bin:/etc:/usr/lbin:/usr/bin/X11:/usr/local/bin
export PATH
LIBRARY_PATH=$ORACLE_HOME/lib32:$LD_LIBRARY_PATH ;export LIBRARY_PATH


current_time=`date '+%Y%m%d'`
dumpfile='expdp_db_zxin_'$current_time'_%U.dmp'
logfile='expdp_db_zxin_'$current_time'.log'
find /oradata1/data_backup/zxin -name "expdp_db_zxin*.dmp" -type f -mtime +1 -exec rm -f {} \;
find /oradata1/data_backup/zxin -name "expdp_db_zxin*.log" -type f -mtime +1 -exec rm -f {} \;
expdp userid=system/*** full=y directory=zxin_expdp_dir filesize=10G dumpfile=$dumpfile logfile=$logfile content=all






ftp_to_p550.sh




#!/bin/bash
current_time=`date '+%Y%m%d'`
ftp -ivn<