Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to ignore some tablespaces when doing physical backup

We have a shell script that perform a physical backup of our oracle database (tar + compress of all our database files). Recently, we created a tablespace containing tables that we dont need to backup its contents.

Is it possible to ignore data files relative to this tablespace and have a valid backup?

PS: we don't want to use RMAN.

like image 604
SamiBOB Avatar asked Dec 07 '25 20:12

SamiBOB


1 Answers

I preface my remarks here with a note: this is NOT the normative pattern. Normally, we use RMAN to backup ALL the datafiles in the database. With that said...


Yes, it may be possible to restore and recover the database from a backup with a m ssing datafile. But the recovery will require that the tablespace be dropped when the database is restored.

For the simple case of a dropping a tablespace that contains a single datafile: first restore the database files, then:


 STARTUP NOMOUNT;

 ALTER DATABASE MOUNT ;

 ALTER DATABASE DATAFILE '<complete_path_to_datafile>' OFFLINE DROP ;

 ALTER DATABASE OPEN ;

 DROP TABLESPACE <tablespace_name> INCLUDING CONTENTS ;

Then, continue with database recovery ( RECOVER DATABASE ; )

Obviously, the tablespace_name you provide in the DROP TABLESPACE command would be the one related to the datafile that is dropped.

Obviously, this wouldn't work for the SYSTEM tablespace. And I wouldn't dare try this on other tablespaces like UNDO, SYSAUX, USERS. And there's different syntax for dropping and adding TEMPORARY TABLESPACES.

I don't know of any "gotchas" with the 'DROP TABLESPACE ... INCLUDING CONTENTS', but consider that objects in other tablespaces could be impacted. (Consider that the dropped tablespace might have indexes for tables in other tablespaces, impacts on foreign key constraints, impacts on stored procedures, and so on.)

And it goes without saying, that you would need to test this type of restore procedure in a test environment before you rely on this technique in production.

Without testing, you would be much better served by using RMAN to backup ALL of the datafiles.


NOTE: I have not done anything like this since Oracle 8, possibly Oracle 7.3 (back when we had to roll our own hotbackup scripts). Since we've started using RMAN, I haven't had a need to test anything like this.

NOTE: The RECOVER DATABASE may need to be run before the ALTER DATABASE OPEN. I think you may get an exception warning about "datafile needing more recovery", like you do when you start the database when a tablespace has been left in BEGIN BACKUP mode...

like image 193
spencer7593 Avatar answered Dec 09 '25 19:12

spencer7593



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!