Oracle Backup and Recovery

1. Backup oracle database steps

Create a new bat file, file content:

@echo off

echo ================================================ 

echo automatic backup script of Oracle database in Windows environment

echo 1. Name the backup file with the current date.

echo 2. Automatically delete backups older than 30 days.

echo ================================================

:: Get the current time in "YYYYMMDD" format.

set BACKUPDATE=%date:~0,4%%date:~5,2%%date:~8,2%

set CURTIME=%time:~0.2%

If REM hours are less than 10, add 0 in front

if "%CURTIME%"==" 0" set CURTIME=00

if "%CURTIME%"==" 1" set CURTIME=01

if "%CURTIME%"==" 2" set CURTIME=02

if "%CURTIME%"==" 3" set CURTIME=03

if "%CURTIME%"==" 4" set CURTIME=04

if "%CURTIME%"==" 5" set CURTIME=05

if "%CURTIME%"==" 6" set CURTIME=06

if "%CURTIME%"==" 7" set CURTIME=07

if "%CURTIME%"==" 8" set CURTIME=08

if "%CURTIME%"==" 9" set CURTIME=09

set CURTIME=%CURTIME%%time:~3.2%%time:~6.2%

 

::Set username, password and database to backup.

set USER=user

set PASSWORD=12345678

set DATABASE=xxx.xxx.xxx.xxx:端口/orcl

::Create a backup directory.

if not exist "D:\backup\data\%BACKUPDATE% "     mkdir D:\backup\data\%BACKUPDATE%

if not exist "D:\backup\log\%BACKUPDATE% "      mkdir D:\backup\log\%BACKUPDATE%

set DATADIR=D:\backup\data\%BACKUPDATE%

set LOGDIR=D:\backup\log\%BACKUPDATE%

exp %USER%/%PASSWORD%@%DATABASE%  file=%DATADIR%\%USER%_%BACKUPDATE%%CURTIME%.dmp log=%LOGDIR%\log_%BACKUPDATE%%CURTIME%.log

:: Delete backups older than 30 days.

forfiles /p "%DATADIR%" /s /m *.* /d -30 /c "cmd /c del @path"

forfiles /p "%LOGDIR%" /s /m *.* /d -30 /c "cmd /c del @path"

exit

 

In the script, there is information such as username and password database instance, and the backup operation can be performed by executing the bat file. Back up all data table data under the current user.

 In addition, if you only need to back up the specified table, you can add the tables command to the exp command and specify the table to be backed up. For example, tables=xxxx, only the contents of the xxxx table will be backed up.

2. Restore the database through the backup dmp file.

In the running cmd command interface, enter the following:

imp cmdiuser/[email protected]:1521/orcl file=D:\backup\

data\20170305\cmdiuser_20170305185046.dmp log=D:\backup\log\20170305\log_2017030

5185046.log tables=(DATA_WELL,CP_COMPREREGION)

 

Among them, file is the backup dmp file, log is the log during backup, and tables is the table to be restored. Multiple tables are separated by commas. If all tables are restored, the log and tables commands are not required.

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326388168&siteId=291194637