quinta-feira, 20 de junho de 2013

Backup RMAN - Alguns scripts

Boa tarde jovens.

Vou postar aqui um script de backup (e suas variações) que está mais que testado e que me ajuda bastante quando preciso fazer algo rápido e manual.

==================
-- Backup
==================
rman target / << EOF
run {
    allocate channel d1 type disk MAXPIECESIZE 8G;
    SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
    SQL 'ALTER SYSTEM CHECKPOINT';
    backup AS COMPRESSED BACKUPSET format '/backups/PROD/%d_%Y%M%D_%I_%s_%U.dat' database;
    sql 'alter system archive log current';
    backup AS COMPRESSED BACKUPSET format '/backups/PROD/%d_%Y%M%D_%I_%s_%U.dat' archivelog all;
    release channel d1;
}
exit;
EOF


==================
-- Backup deletando archives e backupsets
==================
rman target / <

run {
    allocate channel d1 type disk MAXPIECESIZE 8G;
    SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
    SQL 'ALTER SYSTEM CHECKPOINT';
    backup AS COMPRESSED BACKUPSET format '/backups/PROD/%d_%Y%M%D_%I_%s_%U.dat' database;
    sql 'alter system archive log current';
    backup AS COMPRESSED BACKUPSET format '/backups/PROD/%d_%Y%M%D_%I_%s_%U.dat' archivelog all;
    DELETE NOPROMPT ARCHIVELOG UNTIL TIME 'SYSDATE-5';
    DELETE NOPROMPT OBSOLETE DEVICE TYPE DISK;
    release channel d1;
}
exit;
EOF

========================
-- Backup somente de archives
========================
rman target / <

run {
    allocate channel d1 type disk MAXPIECESIZE 8G;
    SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
    SQL 'ALTER SYSTEM CHECKPOINT';
    backup AS COMPRESSED BACKUPSET format '/backups/PROD/%d_%Y%M%D_%I_%s_%U.dat' archivelog all;
    release channel d1;
}
exit;
EOF

Simples e objetivo caso precise rodar algo manualmente.

Abraço
Mario

Formatação de nome de backuppieces do RMAN

Olá pessoal.

Mais uma da séria "Vou postar aqui para não precisar pesquisar depois".

Strings utilizadas para identificar um backuppeace no RMAN.

Syntax:
  %c  The copy number of the backup piece within a set of duplexed backup pieces. If you did not duplex a backup, then this variable is 1 for backup sets and 0 for proxy copies. If one of these commands is enabled, then the variable shows the copy number. The maximum value for %c is 256.

  %d  The name of the database.

  %D  The current day of the month (in format DD)

  %F  Combination of DBID, day, month, year, and sequence into a unique and repeatable generated name.

  %M  The month (format MM)

  %n  The name of the database, padded on the right with x characters to a total length of eight characters. (AKA: Porn star alias name). For example, if the scott is the database name, %n= scottxxx.

  %p  The piece number within the backup set. This value starts at 1 for each backup set and is incremented by 1 as each backup piece is created. Note: If you specify PROXY, then the %p variable must be included in the FORMAT string either explicitly or implicitly within %U.

  %s  The backup set number. This number is a counter in the control file that is incremented for each backup set. The counter value starts at 1 and is unique for the lifetime of the control file. If you restore a backup         control file, then duplicate values can result. Also, CREATE CONTROLFILE initializes the counter back to 1.

  %t  The backup set time stamp, which is a 4-byte value derived as the number of seconds elapsed since a fixed reference time. The combination of %s and %t can be used to form a unique name for  the backup set.

  %T  The year, month, and day (YYYYMMDD)

  %u  An 8-character name constituted by compressed representations of the backup set number and the time the backup set was created.

  %U  A convenient shorthand for %u_%p_%c that guarantees uniqueness in generated backup filenames.
      If you do not specify a format, RMAN uses %U by default.

  %Y  The year (YYYY)

  %%  Specifies the '%' character. e.g. %%Y translates to %Y.

Eu geralmente utilizo: %d_%Y%M%D_%I_%s_%U.rman

Abraço
Mario

Postagem em destaque

[ORACLE] How to move a datafile to a new location in ASM.

Hello everyone! I hope you're doing well! Today, I needed to move a datafile to another ASM Disk Group. The process was simple, but reme...