如何从数据库备份文件中恢复表与数据
以下是ORACLE数据库中通过数据宕方式从备份文件中恢复表与数据的方法:
-----恢复时间如果顺利的话大约要1小时左右。
以下数据表恢复操作需在数据库主机上操作,操作前EAS所有服务需进行停止:
1. 假如将之前备份的d0023_c.dmp(以现场27号晚上备份的文件名为准,此处是举例)文件拷贝到某个目录下,如:d:\oracle11g\backup_files2 如果备份文件在数据库
主机上则告之存放的路径。
2. c:\>sqlplus / as sysdba
3. sql>create directory expdir2 as 'd:\oracle11g\backup_files2; --其中d:\oracle11g\backup_files2为之前备份文件所在的目录
4. sql>grant read,write on directory expdir2 to D0023_C; --如EAS用户名为D0023_C,现场需改成客户那边的EAS数据库用户名,以下都以D0023_C用户为例
5. sql>conn D0023_C/eas
6. sql>create table t_bd_material_bk as select * from t_bd_material;
create table T_BD_MaterialCompanyInfo_bk as select * from T_BD_MaterialCompanyInfo;
create table T_BD_MaterialCost_bk as select * from T_BD_MaterialCost;
create table T_BD_MaterialPurchasing_bk as select * from T_BD_MaterialPurchasing;
create table T_BD_MaterialSales_bk as select * from T_BD_MaterialSales;
create table T_BD_MaterialInventory_bk as select * from T_BD_MaterialInventory ;
create table T_BD_MaterialPlan_bk as select * from T_BD_MaterialPlan;
create table t_bd_multimeasureunit_bk as select * from t_bd_multimeasureunit;
create table t_bd_materialasstattrvalue_bk as select * from t_bd_materialasstattrvalue ;
create table t_bd_materialgroupdetial_bk as select * from t_bd_materialgroupdetial;
create table t_bd_measureunitgrouprelation_bk as select * from t_bd_measureunitgrouprelation;
create table t_bd_measureunitrelation_bk as select * from t_bd_measureunitrelation;
确认以上表都正确备份成功后,将要还原的表进行一一删除:
sql>drop table t_bd_material;
drop table T_BD_MaterialCompanyInfo;
drop table T_BD_MaterialCost;
drop table T_BD_MaterialPurchasing;
drop table T_BD_MaterialSales;
drop table T_BD_MaterialInventory;
drop table T_BD_MaterialPlan;
drop table t_bd_multimeasureunit;
drop table t_bd_materialasstattrvalue;
drop table t_bd_materialgroupdetial;
drop table t_bd_measureunitgrouprelation;
drop table t_bd_measureunitrelation;
紧接着进行以下第7步数据导入(其中dumpfile中的备份文件的名称d0023_c.dmp需改成27晚上备份的文件名称)。
7. c:\>impdp D0023_C/eas tables=t_bd_material,T_BD_MaterialCompanyInfo,T_BD_MaterialCost,T_BD_MaterialPurchasing,T_BD_MaterialSales,T_BD_MaterialInventory,T_BD_MaterialPlan,t_bd_multimeasureunit,t_bd_materialasstattrvalue,t_bd_materialgroupdetial,t_bd_measureunitgrouprelation,t_bd_measureunitrelation dumpfile=d0023_c.dmp logfile=impdp1030_c.log directory=expdir2
8. 将备份后的数据导入到已还原的表中(如果备份完数据后有新增数据,可以通过以下方法进行核对,并把后面新增的数据插入到还原的表中),这步由现场人员自行处理。
现以t_bd_material这个表为例进行举例,其它的按这种方法自行更换表名与条件后去处理,如下所示:
c:\>sqlplus D0023_C/eas
sql>insert into t_bd_material select * from t_bd_material_BK where not exists(select 1 from t_bd_materia where t_bd_materia.FID =t_bd_materia_BK.FID);
其中上面关联条件中的FID是表的主键对应的字段,其它表的处理的条件也是为表主键对应的列去关联。
9. sql>commit; --插入数据提交
以下所有操作完数据校验无误后启EAS所有的服务。
推荐阅读