简体   繁体   English

通过代码从.net备份Oracle数据库

[英]Backup of Oracle database from .net through code

I want to take backup or restore of my oracle database through .Net code. 我想通过.Net代码备份或还原我的Oracle数据库。 I searched a lot but not found any correct solution. 我进行了大量搜索,但未找到任何正确的解决方案。 Like we do backup in SQL server by executing query. 就像我们通过执行查询在SQL Server中进行备份一样。

backup database :DatabaseName to disk = ':DestinationPath

same I want to do in Oracle. 我想在Oracle中做同样的事情。

You can use an Oracle utility like exp/imp or the newer Oracle Data Pump to create database exports (backups), though you have to execute these outside of the database, in a command line/terminal window. 您可以使用exp / imp之类的Oracle实用程序或较新的Oracle Data Pump来​​创建数据库导出(备份),尽管您必须在数据库外部在命令行/终端窗口中执行这些导出。 See this for more information: http://www.oracle-base.com/articles/10g/oracle-data-pump-10g.php 请参阅此以获取更多信息: http : //www.oracle-base.com/articles/10g/oracle-data-pump-10g.php

Update : I stand corrected. 更新 :我已纠正。 A Data Pump job can be started through PL/SQL. 可以通过PL / SQL启动数据泵作业。 Thanks @a-horse-with-no-NAME. 感谢@ a-horse-with-no-NAME。

This article shows how to start a Data Pump job from sql: http://docs.oracle.com/cd/B19306_01/server.102/b14215/dp_api.htm#i1006925 本文介绍如何从sql启动数据泵作业: http : //docs.oracle.com/cd/B19306_01/server.102/b14215/dp_api.htm#i1006925

Careful: a DataPump or Exp Export is not a real Oracle Backup, and you should test to make sure you can restore from the Dump files you're creating. 小心:DataPump或Exp Export并不是真正的 Oracle备份,因此应进行测试以确保可以从正在创建的Dump文件中进行还原。 The closest thing Oracle has to SQL Server's BACKUP DATABASE command is RMAN, and even then it's quite different. Oracle与SQL Server的BACKUP DATABASE命令最接近的是RMAN,即使如此,它也完全不同。 But it is very useful to call from a Batch File. 但是从批处理文件调用非常有用。 I'm both a DBA for SQL Server and Oracle, and the way each Engine performs Backups is one of the biggest differences. 我既是SQL Server的DBA,也是Oracle的DBA,每个引擎执行备份的方式是最大的差异之一。 Exp and Imp are more similar to SQL's bcp commands (but more powerful). Exp和Imp与SQL的bcp命令更相似(但功能更强大)。 Exp won't backup your Controlfile or AchiveLogs, and you may need these in case of a disaster. Exp不会备份您的Controlfile或AchiveLogs,如果发生灾难,您可能会需要它们。 With Exp, make sure you use CONSISTENT=Y option (FLASHBACK_TIME for newer DataPump Export). 对于Exp,请确保使用CONSISTENT = Y选项(FLASHBACK_TIME用于更新的DataPump导出)。 SQL Server backups are much more straight forward, and easier to recover. SQL Server备份更加简单明了,并且更易于恢复。

I found an easy way to take backup of oracle database though code. 我找到了一种通过代码备份oracle数据库的简单方法。 I take credentials from user through code and make dynamically batch file of exp/imp commands. 我通过代码从用户那里获取凭据,并动态制作exp / imp命令的批处理文件。 and run this batch command with process class. 并使用流程类运行此批处理命令。

Thank you all for your responses. 谢谢大家的答复。

OledbCommand cmd=new OledbCommand ("backup database databasename to disk ='C:\databasename.bak'",con);

con.open();

cmd.ExecutenonQuery();

con.close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM