oracle 冷備份

一搭建實驗環境sql

以sys登入oracle數據庫,分別建立表空間yanshu01和yanshu02
建立表空間yanshu_data:
SQL>create  tablespace  yanshu01 datafile 'd:\oracle\product\10.2.0\oradata\test\yanshu01.dbf'  size  100M extent  management  local uniform  size 1M;  本地管理區間 用戶指定大小爲1m
建立表空間yanshu02
SQL>create  tablespace  yanshu02 datafile 'd:\oracle\product\10.2.0\oradata\test\yanshu02.dbf'  size  100M extent  management  local uniform  size 1M;
建立用戶xuwei,並受權
SQL> create user  xuwei identified  by  xuwei1234 default  tablespace  yanshu01
temporary  tablespace  temp
quota  100M  on  yanshu01 該用戶在yanshu01上最多使用100M的空間
quota  100M  on  yanshu02;
受權:
SQL> grant  connect, resource, select any table  to  xuwei ;(直接授予權限)
解鎖sh用戶,在該客戶中有諸如客戶和銷售等在商業公司中常常使用且比較大的表,很是適合作數據的備份與恢復。
SQL>alter user sh identified by sh1234 account unlock;
sh客戶登入,而後作以下操做:
SQL> select * from tab;
SQL> select count(*) from customers;
SQL> select count(*) from sales;
xuwei客戶登入:sqlplusw xuwei/xuwei1234
SQL> create table sales as select * from sh.sales; (建立銷售表像sh裏的表同樣)
SQL> desc sales
下面爲銷售表sales創建3個索引
SQL> create index sales_prod_id_idx on sales(prod_id) tablespace yanshu02;
SQL> create index sales_cust_id_idx on sales(cust_id) tablespace yanshu02;
SQL> create index sales_channel_id_idx on sales(channel_id) tablespace yanshu02;
SQL> create table customers as select * from sh.customers; (建立客戶表)
SQL> desc customers
下面爲客戶表customers創建2個索引
SQL> create index customers_gendar_idx on customers(cust_gender) tablespace yanshu02;
SQL> create index customers_city_idx on customers(cust_city) tablespace yanshu02;
下面驗證表和索引是否建立
SQL>desc user_tables;
SQL> select table_name,tablespace_name from user_tables;
SQL>desc user_indexes;
SQL> select index_name,table_name,tablespace_name,status from user_indexes;
以上環境搭建完成下面來講一說
二數據庫經常使用到的備份
數據庫的全備份:備份數據庫的全部的數據文件和控制文件,
控制文件備份:
數據文件備份:備份單個的數據文件。
表空間備份:備份組成某一表空間的全部的數據文件。
三 冷備份(脫機備份)
1 以sys登入oracle數據庫
SQL> set line 120;
SQL> set pagesize 30
SQL> col name for a60
SQL> select name from v$controlfile;
SQL> col member for a60
SQL> select member from v$logfile;
SQL> col file_name for a60
SQL> col tablespace for a15
SQL> select file_name,tablespace_name from dba_data_files;
SQL> show parameter pfile;
二、 當找到全部的文件以後,對備份磁盤和目錄進行配置(在e盤創建目錄backup):能夠窗口下進行,也能夠dos下進行。
SQL>host (用該命令切換到dos操做系統窗口)
E:>md backup (在e盤創建目錄backup)
E:>cd backup   (進入backup目錄)
三、 而後打開記事本程序寫以下腳本文件,並保存成coolbak.sql腳本文件:
connect sys/xuwei as sysdba
shutdown immediate
host copy D:\oracle\product\10.2.0\oradata\test\*.*  E:\backup\
host copy D:\ORACLE\PRODUCT\10.2.0\db_1\DBS\initdw.ora  E:\backup\dbs\
host copy D:\oracle\product\10.2.0\db_1\database\pwdtest.ora  E:\backup\database\
host copy D:\oracle\product\10.2.0\oradata\test\yanshu01.dbf  E:\backup\disk1\
host copy D:\oracle\product\10.2.0\oradata\test\yanshu02.dbf  E:\backup\disk2\
startup
最後在SQL*Plus下運行該腳本文件coolbak.sql進行脫機備份
SQL> @E:\oracle\mgt\coolbak.sql
四 冷恢復
1用戶xuwei登錄:sqlplusw xuwei/xuwei1234
SQL> select count(*) from sales;
SQL>truncate table sales;
SQL> select * from cat;
SQL> select count(*) from sales;
2以sys登入oracle數據庫
SQL>shutdown immediate
host copy E:\backup\*.*  D:\oracle\product\10.2.0\oradata\test\  
host copy E:\backup\dbs\DBS\initdw.ORA  D:\ORACLE\PRODUCT\10.2.0\DB_1\  
host copy E:\backup\database\pwdtest.ora  D:\oracle\product\10.2.0\db_1\database\  
host copy E:\backup\disk1\yanshu01.DBF  D:\oracle\product\10.2.0\oradata\test\
host copy E:\backup\disk2\yanshu02.DBF  D:\oracle\product\10.2.0\oradata\test
複製完全部的備份文件以後,當即啓動數據庫
SQL>startup
SQL> select count(*) from sales;
相關文章
相關標籤/搜索