Categories
dba rman

Irrecoverable part III : a fix

After part I:the problem, Part II: two reports here is part III.

We have backed up archivelog during a full and deleted them before the full completed.

RMAN> list backup of archivelog all;

List of Backup Sets
===================

BS Size Type Elapsed Completion
-- ------ ---- -------- ----------
15 4.00K DISK 00:00:00 13:31:08
BP Key: 15 Status: AVAILABLE
Piece Name: /FULL/0fq7gc0s_1_1

List of Archived Logs in backup set 15
Seq LowSCN LowTime NextSCN NextTime
--- ------- -------- ------- --------
15 355533 13:29:55 355777 13:31:08

BS Size Type Elapsed Completion
-- ------ ---- -------- ----------
25 4.00K DISK 00:00:00 13:31:26
BP Key: 25 Status: AVAILABLE
Piece Name: /ARCH/0pq7gc1e_1_1

List of Archived Logs in backup set 25
Seq LowSCN LowTime NextSCN NextTime
--- ------- -------- ------- --------
15 355533 13:29:55 355777 13:31:08

BS Size Type Elapsed Completion
-- ------ ---- -------- ----------
26 3.00K DISK 00:00:00 13:31:26
BP Key: 26 Status: AVAILABLE
Piece Name: /ARCH/0qq7gc1e_1_1

List of Archived Logs in backup set 26
Seq LowSCN LowTime NextSCN NextTime
--- ------- -------- ------- --------
16 355777 13:31:08 355827 13:31:22

BS Size Type Elapsed Completion
-- ------ ---- -------- ----------
28 2.50K DISK 00:00:00 13:31:28
BP Key: 28 Status: AVAILABLE
Piece Name: /FULL/0sq7gc1g_1_1

List of Archived Logs in backup set 28
Seq LowSCN LowTime NextSCN NextTime
--- ------- -------- ------- --------
17 355827 13:31:22 355863 13:31:28

Sequence 16 is missing in /FULL/ and is available in /ARCH/

Ok, let’s copy the missing pieces from ARCH to FULL

$ cd /
$ cp -p ARCH/* FULL/

Now let’s try. I save my directory on an offline location (tape/usb/cdrom) and dropped my database including backups.


cd /
tar cvf /tmp/FULL.tar FULL

Let’s drop (it’s just a test)

RMAN> startup force mount dba
RMAN> drop database including backups;
database dropped

Ok let’s get this USB stick back from the moon to my datacenter and see if I can restore …

cd /
tar xvf /tmp/FULL.tar

Let’s do this !

RMAN> startup force nomount
RMAN> restore controlfile from '/FULL/c-2414975447-20150521-01';
RMAN> alter database mount;

Now I want RMAN to look for other files in FULL and also marked expired stuff. The start with does the magic.

RMAN> catalog start with '/FULL/' noprompt;
RMAN> crosscheck backup;
RMAN> crosscheck copy;
RMAN> crosscheck archivelog all;
RMAN> restore database;
RMAN> recover database;
RMAN> alter database open resetlogs;

As @dbastorage said on twitter:
“if it was easy, we would not need DBAs! ”

Categories
dba rman

Irrecoverable full backup part II : reporting

After my post Can you restore from a full online backup ?, I needed to come up with a report.

Assuming that each backup goes in a different directory, I just wrote two reports.

  1. Report gaps in v$backup_redolog (or rc_backup_redolog if you use the catalog)

    DIR FIRST_CHANGE# NEXT_CHANGE#
    ------- ------------- ------------
    /bck01/ 284891 285140
    /bck01/ 285140 285178

    /bck02/ 284891 285140
    === GAP ===
    /bck02/ 285178 285245

    /bck03/ 285178 285245
    /bck03/ 285245 286931
    /bck03/ 286931 287803
    /bck03/ 287803 288148

    This could be done with analytics, by checking where the last next_change is not the current first_change, within a directory

    SELECT dir,
    LAG missing_from_change#,
    first_change# missing_to_change#
    FROM (
    SELECT REGEXP_REPLACE (handle, '[^/\]+$') dir,
    first_change#,
    next_change#,
    LAG(next_change#) OVER (
    PARTITION BY REGEXP_REPLACE (handle, '[^/\]+$')
    ORDER BY first_change#
    ) LAG
    FROM v$backup_piece p
    JOIN v$backup_redolog l
    USING (set_stamp, set_count))
    WHERE LAG != first_change#;

    DIR MISSING_FROM_CHANGE# MISSING_TO_CHANGE#
    ------- -------------------- ------------------
    /bck02/ 285140 285178

  2. Reports directories where archivelogs don’t include changes (backup redolog) from the earliest to the latest checkpoint (backup datafile)

    SELECT
    REGEXP_REPLACE (handle, '[^/\]+$') dir,
    MIN (checkpoint_change#),
    MAX (checkpoint_change#),
    MIN (first_change#),
    MAX (next_change#)
    FROM v$backup_piece p
    LEFT JOIN v$backup_datafile f
    USING (set_stamp, set_count)
    LEFT JOIN v$backup_redolog l
    USING (set_stamp, set_count)
    WHERE handle IS NOT NULL
    HAVING
    MIN (checkpoint_change#) < MIN (first_change#) OR MAX (checkpoint_change#) > MAX (next_change#)
    GROUP BY REGEXP_REPLACE (handle, '[^/\]+$');

    DIR MINCHECKPT MAXCHECKPT MINFIRST MAXNEXT
    ------- ---------- ---------- ---------- ----------
    /bck04/ 954292 954299 959487 1145473

    the archives for the changes from 954292 to 959487 are missing.

If some archive backups are missing in one directory, it does not mean the database is irrecoverable, the archive backups could be in another directory. But it means that single directory would no longer permit you to restore or duplicate.

Another approach with RESTORE PREVIEW was provided by Franck in my previous post : List all RMAN backups that are needed to recover.

Usual disclaimer: there are plenty of other irrecoverabilty causes from hardware defect to backup “optimization” that are beyond the scope of this post.

Categories
dba rman

Can you restore from a full online backup ?

The question is not HOW TO DO IT but WHETHER YOU CAN DO IT !

A typical backup script would contains something like BACKUP DATABASE PLUS ARCHIVELOG:

backup database format
'/u99/backup/DB01/20150518/full_0_%d_s%s_p%p'
plus archivelog format
'/u99/backup/DB01/20150518/arc_%d_s%s_p%p';

Starting backup at 2015-05-18_18:27:55
current log archived
input archived log thread=1 sequence=469
...
piece handle=
/u99/backup/DB01/20150518/arc_DB01_s86_p1
Finished backup at 2015-05-18_18:27:58

Starting backup at 2015-05-18_18:27:58
input datafile file number=00002 name=
/u02/oradata/DB01/undots01.dbf
...
including current control file in backup set
including current SPFILE in backup set
piece handle=
/u99/backup/DB01/20150518/full_0_DB01_s88_p1
Finished backup at 2015-05-18_18:28:16

Starting backup at 2015-05-18_18:28:16
current log archived
input archived log thread=1 sequence=20
piece handle=
/u99/backup/DB01/20150518/arc_DB01_s89_p1
Finished backup at 2015-05-18_18:28:17

This sounds pretty safe, but what happened if you keep this full backup for ever ? do you have all what you need in it to restore ?

It depends. Chance exists that you can restore. To annoy the paranoiacs, here is a counter example.

  1. you start your full backup at 6pm.
    backuping sequence 21,22,23,24
    backup datafiles…

  2. at 7 pm one cronjob issue backup archivelog all delete input;
    backuping and deleting sequence 21,22,23,24,25,26,27,28,29,30

  3. at 8pm your backup is about to finish
    backuping sequence 31

Well, where is my sequence 27 ?

Let’s try

rm /tmp/arch_DB01*
startup force mount;
crosscheck backup;restore database;


Starting restore at 2015-05-18_18:47:45
channel ORA_DISK_1: restore complete, elapsed time: 00:02:05
Finished restore at 2015-05-18_18:49:51

Ok, the restore was fine. Now what?

RMAN> recover database;

Starting recover at 2015-05-18_18:50:35
using channel ORA_DISK_1

starting media recovery

RMAN-00571: =================================================
RMAN-00569: ========== ERROR MESSAGE STACK FOLLOWS ==========
RMAN-00571: =================================================
RMAN-03002: failure of recover command at 05/18/2015 18:50:36
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of archived log for thread 1 with sequence 30
RMAN-06025: no backup of archived log for thread 1 with sequence 29
RMAN-06025: no backup of archived log for thread 1 with sequence 27

RMAN> alter database open;

RMAN-00571: =================================================
RMAN-00569: ========== ERROR MESSAGE STACK FOLLOWS ==========
RMAN-00571: =================================================
RMAN-03002: failure of alter db command at 05/18/2015 18:51:29
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/u02/oradata/DB01/system01.dbf'

You have lost your database. Even if you did a full online backup plus archivelog, it did not contain all the archivelogs and RMAN did not tell you.

There is more than one way to reduce this annoyance :

1) don’t backup archivelogs during full backup
2) don’t delete archivelog backups done during a full backup
3) report any archivelog backups that run during a full. Either by looking in the RMAN dictionary or in your house logfiles
4) do offline backup for long term archives
5) don’t trust RMAN

And as well :
Test your backups 😀

Categories
Uncategorized

🎂 10 years 🎂

Thanks to all my readers for being so faithful 🙂
I’ll post a new solution to calculate factorial.

This is the one I posted 10 years ago :
https://laurentschneider.com/2005/05/recursive-sql.html

I also used it in the obfuscation contest

with function f (x number) return number
is
begin
return case x when 1 then x else x*f(x-1) end;
end;
select value(t), f(value(t))
from table(sys.odcinumberlist(4,6))t

VALUE(T) F(VALUE(T))
---------- -----------
4 24
6 720

It is neither quicker nor shorter than the one I posted in 2005, but it could not have worked in 2005