Podemos realizar backup de nossos DB Systems através da OCI Console, API, RMAN ou pelo utilitário DBCLI. Neste artigo, vamos simular a utilização do DBCLI. Este método nos permite realizar os backups em disco (DISK) ou diretamente no OCI Object Storage (OBJECTSTORE), além de conseguirmos definir o tempo de retenção dos mesmos (Recovery Window), por número de dias. Vale lembrar que não é possível realizar o RESTORE do ambiente pelo DBCLI. Neste caso, seria necessário o bom e velho RMAN.
Logado com o usuário root, criamos um “Backup Configuration” populado com os parâmetros do exemplo abaixo:
[opc@luxor ~]$ sudo su -
Last login: Tue Jul 13 22:49:02 UTC 2021
[root@luxor ~]# dbcli create-backupconfig --name CORTEXBKP --backupdestination disk --recoverywindow 5
{
"jobId" : "8ace01bf-2b8c-40d6-9581-ada419506ccf",
"status" : "Created",
"message" : "backup config creation",
"reports" : [ ],
"createTimestamp" : "July 13, 2021 22:53:41 PM UTC",
"resourceList" : [ {
"resourceId" : "ef04e57f-3a8a-42c1-be03-21e816025085",
"resourceType" : "BackupConfig",
"jobId" : "8ace01bf-2b8c-40d6-9581-ada419506ccf",
"updatedTime" : "July 13, 2021 22:53:42 PM UTC"
} ],
"description" : "create backup config:CORTEXBKP",
"updatedTime" : "July 13, 2021 22:53:42 PM UTC",
"percentageProgress" : "0%"
}
Acompanhando o Job de criação do BC:
[root@luxor ~]# dbcli describe-job -i "8ace01bf-2b8c-40d6-9581-ada419506ccf"
Job details
----------------------------------------------------------------
ID: 8ace01bf-2b8c-40d6-9581-ada419506ccf
Description: create backup config:CORTEXBKP
Status: Success
Created: July 13, 2021 10:53:41 PM UTC
Progress: 100%
Message: backup config creation
Task Name Start Time End Time Status
------------------------------------------------------------------------ ----------------------------------- ----------------------------------- ----------
Create Backup Configuration July 13, 2021 10:53:42 PM UTC July 13, 2021 10:53:43 PM UTC Success
Podemos ver a existência do BC com o comando abaixo:
[root@luxor ~]# dbcli list-backupconfigs
ID Name RecoveryWindow CrosscheckEnabled BackupDestination
---------------------------------------- -------------------- ---------------- ------------------- --------------------
ef04e57f-3a8a-42c1-be03-21e816025085 CORTEXBKP 5 true Disk
E os detalhes do BC com o exemplo abaixo (inclusive o seu ID, que usaremos em breve):
[root@luxor ~]# dbcli describe-backupconfig -in CORTEXBKP
Backup Config details
----------------------------------------------------------------
ID: ef04e57f-3a8a-42c1-be03-21e816025085
Name: CORTEXBKP
CrosscheckEnabled: true
RecoveryWindow: 5
BackupDestination: Disk
BackupLocation:
ObjectStoreId:
CreatedTime: July 13, 2021 10:53:41 PM UTC
UpdatedTime: July 13, 2021 10:53:43 PM UTC
LocationAffinity:
RecoveryTag:
[root@luxor ~]#
Agora podemos coletar o ID do nosso database:
[root@luxor ~]# dbcli list-databases
ID DB Name DB Type DB Version CDB Class Shape Storage Status DbHomeID
---------------------------------------- ---------- -------- -------------------- ---------- -------- -------- ---------- ------------ ----------------------------------------
4c906765-68ea-4e05-ba3f-c54152f912cf CORTEX Si 19.11.0.0.0 true Oltp ASM Configured d08b9441-b181-42b1-b6be-11616fa9580c
O que é importante notarmos: os parâmetros do RMAN antes e depois de associarmos o BC com o database. Reparemos o valor dos parâmetros abaixo antes da alteração:
[opc@luxor ~]$ sudo su - oracle
Last login: Tue Jul 13 23:07:20 UTC 2021
[oracle@luxor ~]$ rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Tue Jul 13 23:07:55 2021
Version 19.11.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: CORTEX (DBID=581933924)
RMAN> SHOW RETENTION POLICY;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name CORTEX_PHX1HB are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
RMAN> SHOW DEFAULT DEVICE TYPE
2> ;
RMAN configuration parameters for database with db_unique_name CORTEX_PHX1HB are:
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
Vamos associar o database com o BC:
[root@luxor ~]# dbcli update-database --backupconfigid ef04e57f-3a8a-42c1-be03-21e816025085 --dbid 4c906765-68ea-4e05-ba3f-c54152f912cf
{
"jobId" : "35b9609a-b7fa-45b9-b6fa-f61b1e936ff8",
"status" : "Created",
"message" : "update database",
"reports" : [ ],
"createTimestamp" : "July 13, 2021 23:10:29 PM UTC",
"resourceList" : [ {
"resourceId" : "4c906765-68ea-4e05-ba3f-c54152f912cf",
"resourceType" : "DB",
"jobId" : "35b9609a-b7fa-45b9-b6fa-f61b1e936ff8",
"updatedTime" : "July 13, 2021 23:10:30 PM UTC"
} ],
"description" : "update database : CORTEX",
"updatedTime" : "July 13, 2021 23:10:36 PM UTC",
"percentageProgress" : "0%"
}
Acompanhando o Job:
[root@luxor ~]# dbcli describe-job -i "35b9609a-b7fa-45b9-b6fa-f61b1e936ff8"
Job details
----------------------------------------------------------------
ID: 35b9609a-b7fa-45b9-b6fa-f61b1e936ff8
Description: update database : CORTEX
Status: Running
Created: July 13, 2021 11:10:29 PM UTC
Progress: 71%
Message: update database
Task Name Start Time End Time Status
------------------------------------------------------------------------ ----------------------------------- ----------------------------------- ----------
Configure Database for Backup July 13, 2021 11:10:37 PM UTC July 13, 2021 11:10:37 PM UTC Running
[root@luxor ~]# dbcli describe-job -i "35b9609a-b7fa-45b9-b6fa-f61b1e936ff8"
Job details
----------------------------------------------------------------
ID: 35b9609a-b7fa-45b9-b6fa-f61b1e936ff8
Description: update database : CORTEX
Status: Success
Created: July 13, 2021 11:10:29 PM UTC
Progress: 100%
Message: update database
Task Name Start Time End Time Status
------------------------------------------------------------------------ ----------------------------------- ----------------------------------- ----------
Configure Database for Backup July 13, 2021 11:10:37 PM UTC July 13, 2021 11:13:17 PM UTC Success
Agora vemos que a associação do BC ao database teve reflexo nos parâmetros do RMAN (especificamente ao de retenção, já que o de device type continuará como DISK):
[oracle@luxor ~]$ rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Tue Jul 13 23:15:22 2021
Version 19.11.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: CORTEX (DBID=581933924)
RMAN> SHOW RETENTION POLICY;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name CORTEX_PHX1HB are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 5 DAYS;
RMAN> SHOW DEFAULT DEVICE TYPE;
RMAN configuration parameters for database with db_unique_name CORTEX_PHX1HB are:
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
Constatando que meu DB ainda não possui backup:
RMAN> LIST BACKUP OF DATABASE;
specification does not match any backup in the repository
Realizando o backup do nosso banco CORTEX com o DBCLI:
[root@luxor ~]# dbcli create-backup --dbName CORTEX --backupType Regular-L0 --tag CORTEX_L0
{
"jobId" : "1dba6630-8bd9-4210-9244-77c084ad55b6",
"status" : "Created",
"message" : null,
"reports" : [ ],
"createTimestamp" : "July 13, 2021 23:18:55 PM UTC",
"resourceList" : [ ],
"description" : "Create Regular-L0 Backup with TAG-CORTEX_L0 for Db:CORTEX in FRA",
"updatedTime" : "July 13, 2021 23:18:58 PM UTC",
"percentageProgress" : "0%"
}
Acompanhando Job:
[root@luxor ~]# dbcli describe-job -i "1dba6630-8bd9-4210-9244-77c084ad55b6"
Job details
----------------------------------------------------------------
ID: 1dba6630-8bd9-4210-9244-77c084ad55b6
Description: Create Regular-L0 Backup with TAG-CORTEX_L0 for Db:CORTEX in FRA
Status: Running
Created: July 13, 2021 11:18:55 PM UTC
Progress: 1%
Message:
Task Name Start Time End Time Status
------------------------------------------------------------------------ ----------------------------------- ----------------------------------- ----------
Validate Database backup Configuration July 13, 2021 11:18:58 PM UTC July 13, 2021 11:18:58 PM UTC Running
[root@luxor ~]# dbcli describe-job -i "1dba6630-8bd9-4210-9244-77c084ad55b6"
Job details
----------------------------------------------------------------
ID: 1dba6630-8bd9-4210-9244-77c084ad55b6
Description: Create Regular-L0 Backup with TAG-CORTEX_L0 for Db:CORTEX in FRA
Status: Running
Created: July 13, 2021 11:18:55 PM UTC
Progress: 25%
Message:
Task Name Start Time End Time Status
------------------------------------------------------------------------ ----------------------------------- ----------------------------------- ----------
Validate Database backup Configuration July 13, 2021 11:18:58 PM UTC July 13, 2021 11:19:59 PM UTC Success
Backup Database July 13, 2021 11:19:59 PM UTC July 13, 2021 11:19:59 PM UTC Running
[root@luxor ~]# dbcli describe-job -i "1dba6630-8bd9-4210-9244-77c084ad55b6"
Job details
----------------------------------------------------------------
ID: 1dba6630-8bd9-4210-9244-77c084ad55b6
Description: Create Regular-L0 Backup with TAG-CORTEX_L0 for Db:CORTEX in FRA
Status: Success
Created: July 13, 2021 11:18:55 PM UTC
Progress: 100%
Message:
Task Name Start Time End Time Status
------------------------------------------------------------------------ ----------------------------------- ----------------------------------- ----------
Validate Database backup Configuration July 13, 2021 11:18:58 PM UTC July 13, 2021 11:19:59 PM UTC Success
Backup Database July 13, 2021 11:19:59 PM UTC July 13, 2021 11:24:33 PM UTC Success
Validate the backup July 13, 2021 11:24:33 PM UTC July 13, 2021 11:24:47 PM UTC Success
Backup TDE Wallet. July 13, 2021 11:24:47 PM UTC July 13, 2021 11:24:47 PM UTC Success
O RMAN já faz o reconhecimento dos backup pieces gerados pelo processo:
RMAN> LIST BACKUP OF DATABASE TAG CORTEX_L0;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
10 Incr 0 514.76M DISK 00:00:25 13-JUL-21
BP Key: 10 Status: AVAILABLE Compressed: YES Tag: CORTEX_L0
Piece Name: +RECO/CORTEX_PHX1HB/BACKUPSET/2021_07_13/nnndn0_cortex_l0_0.298.1077837775
List of Datafiles in backup set 10
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- --------- ----------- ------ ----
1 0 Incr 6122522 13-JUL-21 NO +DATA/CORTEX_PHX1HB/DATAFILE/system.261.1071999329
3 0 Incr 6122522 13-JUL-21 NO +DATA/CORTEX_PHX1HB/DATAFILE/sysaux.262.1071999373
4 0 Incr 6122522 13-JUL-21 NO +DATA/CORTEX_PHX1HB/DATAFILE/undotbs1.263.1071999399
11 0 Incr 6122522 13-JUL-21 NO +DATA/CORTEX_PHX1HB/DATAFILE/users.274.1072000383
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
11 Incr 0 253.48M DISK 00:00:18 13-JUL-21
BP Key: 11 Status: AVAILABLE Compressed: YES Tag: CORTEX_L0
Piece Name: +RECO/CORTEX_PHX1HB/C1CF6DCEA12F134DE0539501000A20C1/BACKUPSET/2021_07_13/nnndn0_cortex_l0_0.299.1077837801
List of Datafiles in backup set 11
Container ID: 3, PDB Name: HIPOFISE1
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- --------- ----------- ------ ----
8 0 Incr 6122540 13-JUL-21 NO +DATA/CORTEX_PHX1HB/C1CF6DCEA12F134DE0539501000A20C1/DATAFILE/system.271.1072000035
9 0 Incr 6122540 13-JUL-21 NO +DATA/CORTEX_PHX1HB/C1CF6DCEA12F134DE0539501000A20C1/DATAFILE/sysaux.272.1072000035
10 0 Incr 6122540 13-JUL-21 NO +DATA/CORTEX_PHX1HB/C1CF6DCEA12F134DE0539501000A20C1/DATAFILE/undotbs1.270.1072000035
12 0 Incr 6122540 13-JUL-21 NO +DATA/CORTEX_PHX1HB/C1CF6DCEA12F134DE0539501000A20C1/DATAFILE/users.275.1072000383
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
12 Incr 0 316.40M DISK 00:00:10 13-JUL-21
BP Key: 12 Status: AVAILABLE Compressed: YES Tag: CORTEX_L0
Piece Name: +RECO/CORTEX_PHX1HB/C1CF50B886E7568DE0539501000A38F1/BACKUPSET/2021_07_13/nnndn0_cortex_l0_0.300.1077837825
List of Datafiles in backup set 12
Container ID: 2, PDB Name: PDB$SEED
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- --------- ----------- ------ ----
5 0 Incr 5899769 05-JUN-21 NO +DATA/CORTEX_PHX1HB/B2084748142A4638E053C003F40A65C0/DATAFILE/system.266.1071999505
6 0 Incr 5899769 05-JUN-21 NO +DATA/CORTEX_PHX1HB/B2084748142A4638E053C003F40A65C0/DATAFILE/sysaux.265.1071999505
7 0 Incr 5899769 05-JUN-21 NO +DATA/CORTEX_PHX1HB/B2084748142A4638E053C003F40A65C0/DATAFILE/undotbs1.267.1071999505
Caso precisemos alterar algum valor de parâmetro do nosso BC, podemos realizar conforme exemplo abaixo:
[root@luxor ~]# dbcli update-backupconfig -in CORTEXBKP --recoverywindow 6
{
"jobId" : "7f6d7aee-e05f-4620-bc2b-7a0109f1f9a8",
"status" : "Created",
"message" : "backup config",
"reports" : [ ],
"createTimestamp" : "July 13, 2021 23:29:58 PM UTC",
"resourceList" : [ {
"resourceId" : "ef04e57f-3a8a-42c1-be03-21e816025085",
"resourceType" : "BackupConfig",
"jobId" : "7f6d7aee-e05f-4620-bc2b-7a0109f1f9a8",
"updatedTime" : "July 13, 2021 23:29:59 PM UTC"
} ],
"description" : "update backup config: CORTEXBKP",
"updatedTime" : "July 13, 2021 23:30:02 PM UTC",
"percentageProgress" : "0%"
}
[root@luxor ~]# dbcli describe-job -i "7f6d7aee-e05f-4620-bc2b-7a0109f1f9a8"
Job details
----------------------------------------------------------------
ID: 7f6d7aee-e05f-4620-bc2b-7a0109f1f9a8
Description: update backup config: CORTEXBKP
Status: Success
Created: July 13, 2021 11:29:58 PM UTC
Progress: 100%
Message: backup config
Task Name Start Time End Time Status
------------------------------------------------------------------------ ----------------------------------- ----------------------------------- ----------
Update Backup Configuration July 13, 2021 11:30:02 PM UTC July 13, 2021 11:31:33 PM UTC Success
Examinando o reflexo da mudança no parâmetro do RMAN:
RMAN> SHOW RETENTION POLICY;
RMAN configuration parameters for database with db_unique_name CORTEX_PHX1HB are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 6 DAYS;
Como mencionado no começo do artigo, o evento de restore não pode ser feito pelo DBCLI, mas o RMAN tem totais condições de fazê-lo utilizando o backup realizado pelo DBCLI. Vamos realizar o teste:
[oracle@luxor ~]$ rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Tue Jul 13 23:34:34 2021
Version 19.11.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: CORTEX (DBID=581933924)
RMAN> SHUTDOWN IMMEDIATE;
using target database control file instead of recovery catalog
database closed
database dismounted
Oracle instance shut down
RMAN> STARTUP MOUNT;
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area 6442449664 bytes
Fixed Size 9149184 bytes
Variable Size 1577058304 bytes
Database Buffers 4831838208 bytes
Redo Buffers 24403968 bytes
RMAN> RESTORE DATABASE FROM TAG CORTEX_L0;
Starting restore at 13-JUL-21
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=28 device type=DISK
skipping datafile 5; already restored to file +DATA/CORTEX_PHX1HB/B2084748142A4638E053C003F40A65C0/DATAFILE/system.266.1071999505
skipping datafile 6; already restored to file +DATA/CORTEX_PHX1HB/B2084748142A4638E053C003F40A65C0/DATAFILE/sysaux.265.1071999505
skipping datafile 7; already restored to file +DATA/CORTEX_PHX1HB/B2084748142A4638E053C003F40A65C0/DATAFILE/undotbs1.267.1071999505
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to +DATA/CORTEX_PHX1HB/DATAFILE/system.261.1071999329
channel ORA_DISK_1: restoring datafile 00003 to +DATA/CORTEX_PHX1HB/DATAFILE/sysaux.262.1071999373
channel ORA_DISK_1: restoring datafile 00004 to +DATA/CORTEX_PHX1HB/DATAFILE/undotbs1.263.1071999399
channel ORA_DISK_1: restoring datafile 00011 to +DATA/CORTEX_PHX1HB/DATAFILE/users.274.1072000383
channel ORA_DISK_1: reading from backup piece +RECO/CORTEX_PHX1HB/BACKUPSET/2021_07_13/nnndn0_cortex_l0_0.298.1077837775
channel ORA_DISK_1: piece handle=+RECO/CORTEX_PHX1HB/BACKUPSET/2021_07_13/nnndn0_cortex_l0_0.298.1077837775 tag=CORTEX_L0
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00008 to +DATA/CORTEX_PHX1HB/C1CF6DCEA12F134DE0539501000A20C1/DATAFILE/system.271.1072000035
channel ORA_DISK_1: restoring datafile 00009 to +DATA/CORTEX_PHX1HB/C1CF6DCEA12F134DE0539501000A20C1/DATAFILE/sysaux.272.1072000035
channel ORA_DISK_1: restoring datafile 00010 to +DATA/CORTEX_PHX1HB/C1CF6DCEA12F134DE0539501000A20C1/DATAFILE/undotbs1.270.1072000035
channel ORA_DISK_1: restoring datafile 00012 to +DATA/CORTEX_PHX1HB/C1CF6DCEA12F134DE0539501000A20C1/DATAFILE/users.275.1072000383
channel ORA_DISK_1: reading from backup piece +RECO/CORTEX_PHX1HB/C1CF6DCEA12F134DE0539501000A20C1/BACKUPSET/2021_07_13/nnndn0_cortex_l0_0.299.1077837801
channel ORA_DISK_1: piece handle=+RECO/CORTEX_PHX1HB/C1CF6DCEA12F134DE0539501000A20C1/BACKUPSET/2021_07_13/nnndn0_cortex_l0_0.299.1077837801 tag=CORTEX_L0
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 13-JUL-21
RMAN> RECOVER DATABASE;
Starting recover at 13-JUL-21
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:06
Finished recover at 13-JUL-21
RMAN> ALTER DATABASE OPEN;
Statement processed
RMAN> SELECT NAME,OPEN_MODE FROM GV$DATABASE;
NAME OPEN_MODE
--------- --------------------
CORTEX READ WRITE
Obs: Este procedimento foi criado pelo senhor Ahmed Baraka (www.ahmedbaraka.com) e foi apenas reproduzido por mim em um laboratório pessoal para fins de aprendizado.