oracle Database Creation Backup and Recovery Script Arrangement

  • 2021-07-10 21:04:43
  • OfStack

1: Create a user
 
create temporary tablespace user_temp 
tempfile 'D:\app\topwqp\oradata\orcl\user_temp.dbf' 
size 500m 
autoextend on 
next 50m maxsize 2048m 
extent management local; 
create tablespace ts_mydb 
logging 
datafile 'D:\app\topwqp\oradata\orcl\ts_mydb.dbf' 
size 500m 
autoextend on 
next 50m maxsize 2048m 
extent management local; 
drop user mydb cascade; 
create user mydb identified by mydb 
default tablespace ts_mydb 
temporary tablespace user_temp; 
grant connect,resource,dba to mydb; 

Meaning of the above command:
Create a temporary tablespace, temporary file name: is the actual file stored by oracle, size is the size of this file, and autoextend is the extended size when the capacity is full.
Before creating a user, delete the user information in cascade,
Then create the user's username and password, and finally authorize the user. Here, connect, resource and dba are granted three permissions, and the detailed authorization is checked again.
2: Import the database
 
SET USERID=mydb/mydb@orcl 
SET FROMUSER=test 
SET TOUSER=mydb 
SET FILENAME=test_bak2013-03-22.dmp 
SET LOGNAME=mylog.log 
imp %USERID% file=%FILENAME% fromuser=%FROMUSER% touser=%TOUSER% log=%LOGNAME% 

Where userid is used to import the user name/password and database name of the database you want to import,
FROMUSER is used to refer to the user name of the database being backed up, TOUSER is used to refer to the user in the database to be imported, and FILENAME is used to specify the backup dmp database file required for import.

LOGNAME represents the log file. Note that the imported database must be placed in the same location as this script.
Usage: copy above code saved to. bat file, and then double-click to execute.
3: Export the database
 
SET CURDATE=%date:~0,10% 
SET USERID=test/test@orcl 
SET OWNER=test 
SET FILENAME=test_bak%CURDATE%.dmp 
SET LOGNAME=test_bak%CURDATE%.log 
exp %USERID% file=%FILENAME% owner=%OWNER% log=%LOGNAME% 

Where userid is the imported user name and password, curdate is used to obtain the current date, OWNER is used to explain which user is exported, FILENAME is the exported file name, LOGNAME is the exported log file,
Then execute the export command.

Related articles: