简体   繁体   English

使用 sqlplus 或 rman 进行 oracle 10g 测试的备份/恢复数据库

[英]Backup/Restore database for oracle 10g testing using sqlplus or rman

Using Oracle 10g with our testing server what is the most efficient/easy way to backup and restore a database to a static point, assuming that you always want to go back to the given point once a backup has been created.将 Oracle 10g 与我们的测试服务器一起使用,将数据库备份和还原到 static 点的最有效/最简单的方法是什么,假设您总是想要 Z34D1F91FB2E514B8576FAB1A75A 备份到 A9 点。

A sample use case would be the following示例用例如下

  1. install and configure all software安装和配置所有软件
  2. Modify data to the base testing point修改数据到基础测试点
  3. take a backup somehow (this is part of the question, how to do this)以某种方式进行备份(这是问题的一部分,如何做到这一点)
  4. do testing做测试
  5. return to step 3 state (restore back to backup point, this is the other half of the question)返回步骤 3 state (恢复到备份点,这是问题的另一半)

Optimally this would be completed through sqlplus or rman or some other scriptable method.理想情况下,这将通过 sqlplus 或 rman 或其他一些可编写脚本的方法来完成。

You do not need to take a backup at your base time.您无需在基准时间进行备份。 Just enable flashback database, create a guaranteed restore point, run your tests and flashback to the previously created restore point.只需启用闪回数据库,创建保证还原点,运行测试并闪回到之前创建的还原点。

The steps for this would be:这样做的步骤是:

  1. Startup the instance in mount mode.以挂载模式启动实例。

    startup force mount;启动力安装;

  2. Create the restore point.创建还原点。

    create restore point before_test guarantee flashback database;创建还原点 before_test 保证闪回数据库;

  3. Open the database.打开数据库。

    alter database open;更改数据库打开;

  4. Run your tests.运行你的测试。

  5. Shutdown and mount the instance.关闭并挂载实例。

    shutdown immediate;立即关机; startup mount;启动挂载;

  6. Flashback to the restore point.闪回还原点。

    flashback database to restore point before_test;闪回数据库到还原点 before_test;

  7. Open the database.打开数据库。

    alter database open;更改数据库打开;

You could use a feature in Oracle called Flashback which allows you to create a restore point, which you can easily jump back to after you've done testing.您可以使用 Oracle 中称为Flashback的功能,它允许您创建一个还原点,您可以在完成测试后轻松跳回该还原点。

Quoted from the site,引自网站,

Flashback Database is like a 'rewind button' for your database.闪回数据库就像您的数据库的“倒带按钮”。 It provides database point in time recovery without requiring a backup of the database to first be restored.它提供数据库时间点恢复,而无需首先恢复数据库的备份。 When you eliminate the time it takes to restore a database backup from tape, database point in time recovery is fast.当您消除从磁带恢复数据库备份所需的时间时,数据库时间点恢复速度很快。

From my experience import/export is probably the way to go.根据我的经验,导入/导出可能是通往 go 的方式。 Export creates a logical snapshot of your DB so you won't find it useful for big DBs or exacting performance requirements.导出创建数据库的逻辑快照,因此您不会发现它对大型数据库或严格的性能要求有用。 However it works great for making snapshots and whatnot to use on a number of machines.然而,它非常适合制作快照以及不能在许多机器上使用的东西。

I used it on a rails project to get a prod snapshot that we could swap between developers for integration testing and we did the job within rake scripts.我在 Rails 项目中使用它来获取产品快照,我们可以在开发人员之间交换以进行集成测试,并且我们在 rake 脚本中完成了这项工作。 We wrote a small sqlplus script that destroyed the DB then imported the dump file over the top.我们编写了一个小的 sqlplus 脚本,它破坏了数据库,然后在顶部导入了转储文件。

Some articles you may want to check: OraFAQ Cheatsheet Oracle Wiki您可能想要查看的一些文章: OraFAQ Cheatsheet Oracle Wiki

Oracle apparently don't like imp/exp any more in favour of data pump , when we used data pump we needed things we couldn't have (ie SYSDBA privileges we couldn't get in a shared environment). Oracle 显然不再喜欢 imp/exp 支持数据泵,当我们使用数据泵时,我们需要我们无法拥有的东西(即我们无法在共享环境中获得的 SYSDBA 权限)。 So take a look but don't be disheartened if data pump is not your bag, the old imp/exp are still there:)所以看看,但如果数据泵不是你的包,请不要灰心,旧的 imp/exp 仍然存在:)

I can't recommend RMAN for this kind of thing becuase RMAN takes a lot of setup and will need config in the DB (it also has its own catalog DB for backups which is a pain in the proverbial for a bare metal restore).我不能为这种事情推荐 RMAN,因为 RMAN 需要进行大量设置并且需要在数据库中进行配置(它也有自己的目录数据库用于备份,这在众所周知的裸机还原中很痛苦)。

If you are using a filesystem that supports copy-on-write snapshots, you could set up the database to the state that you want.如果您使用支持写时复制快照的文件系统,您可以将数据库设置为您想要的 state。 Then shut down everything and take a filesystem snapshot.然后关闭一切并拍摄文件系统快照。 Then go about your testing and when you're ready to start over you could roll back the snapshot.然后 go 关于您的测试,当您准备好重新开始时,您可以回滚快照。 This might be simpler than other options, assuming you have a filesystem which supports snapshots.假设您有一个支持快照的文件系统,这可能比其他选项更简单。

@Michael Ridley solution is perfectly scriptable, and will work with any version of oracle. @Michael Ridley 解决方案完全可以编写脚本,并且适用于任何版本的 oracle。

This is exactly what I do, I have a script which runs weekly to这正是我所做的,我有一个每周运行的脚本

  1. Rollback the file system回滚文件系统
  2. Apply production archive logs应用生产归档日志
  3. Take new "Pre-Data-Masking" FS snapshot拍摄新的“Pre-Data-Masking”FS 快照
  4. Reset logs重置日志
  5. Apply "preproduction" data masking.应用“预生产”数据屏蔽。
  6. Take new "Post-Data-Masking" snapshot (allows rollback to post masked data)拍摄新的“Post-Data-Masking”快照(允许回滚以发布屏蔽数据)
  7. Open database打开数据库

This allows us to keep our development databases close to our production database.这使我们能够将我们的开发数据库保持在我们的生产数据库附近。

To do this I use ZFS.为此,我使用 ZFS。

This method can also be used for your applications, or even you entire "environment" (eg, you could "rollback" your entire environment with a single (scripted) command.此方法也可用于您的应用程序,甚至您的整个“环境”(例如,您可以使用单个(脚本)命令“回滚”整个环境。

If you are running 10g though, the first thing you'd probably want to look into is Flashback, as its built into the database.但是,如果您运行的是 10g,那么您可能首先要研究的是 Flashback,因为它内置在数据库中。

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

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