oracle 冷備份

一搭建實驗環境

以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  xuwei1234default  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;
2、當找到所有的文件之後,對備份磁盤和目錄進行配置(在e盤建立目錄backup):可以窗口下進行,也可以dos下進行。
SQL>host (用該命令切換到dos操作系統窗口)
E:>md backup (在e盤建立目錄backup)
E:>cd backup   (進入backup目錄)
3、然後打開記事本程序寫如下腳本文件,並保存成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;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章