Restoring and upgrading Oracle DB to 19c in one shot with Docker

Marcelo Ochoa
3 min readAug 12, 2020
Photo by Miguel Andrade on Unsplash

Imagine that you have a 12c/18c Oracle RDBMS running on Docker and want to migrate them to 19c.

Using Oracle Docker official image scripts and a two simple bash script will be enough to do this in one shot.

Preparing an RMAN full backup

First you need an RMAN full backup from your 12c/18c database, for doing that We need only a simple bash script passed to the setup/startup hooks of Oracle Docker image.

Directory hooks included into Oracle Docker images are:

setup scripts are executed just after the RDBMS was created and startup scripts are executed right after every Oracle startup. Assuming that you have for example a 12c RDBMS up and running put zz-backup-full.sh at startup directory stop and start again, for the example below We test our procedure by using a 12c fresh instance so We will use setup directory, here zz-backup-full.sh:

and the steps to get a RMAN full backup are:

# mkdir /tmp/setup
# cat > /tmp/setup/zz-backup-full.sh
..... paste above content here .....
# chmod +x /tmp/setup/zz-backup-full.sh
# chown -R 54321:54321 /tmp/setup
# docker run -ti --rm --name freshdb -v /tmp/setup:/opt/oracle/scripts/setup -v /run/shm:/dev/shm oracle/database:12.2.0.1-ee
....... wait to DATABASE IS READY TO USE! message .......
# docker stop freshdb

Note: Owner of /tmp/setup must be 54321:54321 in order RMAN full backup works

Once zz-backup-full.sh finish the content of /tmp/setup directory will look like:

# ll
total 683816
drwxr-xr-x 2 oracle oinstall 4096 ago 12 17:10 ./
drwxrwxrwt 26 root root 20480 ago 12 17:10 ../
-rw-r----- 1 oracle oinstall 338280448 ago 12 13:50 01v7mglm_1_1
-rw-r----- 1 oracle oinstall 171671552 ago 12 13:51 02v7mgn3_1_1
-rw-r----- 1 oracle oinstall 171327488 ago 12 13:51 03v7mgns_1_1
-rw-r----- 1 oracle oinstall 18792448 ago 12 13:51 control.bks
-rw-r----- 1 oracle oinstall 114688 ago 12 13:51 spfile.bks
-rwxr-xr-x 1 oracle oinstall 680 ago 12 13:40 zz-backup-full.sh*

Above content is an RMAN full backup compressed included RDBMS pfile and control file.

To restore and upgrade in one shot We will override 19c createDB.sh script with a new one named upgradeDB.sh as is:

upgradeDB.sh

starting and migrating to 19c using /tmp/setup content directory:

# rm /tmp/setup/zz-backup-full.sh
# cat > /tmp/upgradeDB.sh
..... paste here above content or download from gits .....
# chmod +x /tmp/upgradeDB.sh
# docker run -ti --name newdb -v /tmp/setup:/opt/oracle/scripts/setup -v /tmp/upgradeDB.sh:/opt/oracle/createDB.sh -v /run/shm:/dev/shm oracle/database:19.3.0-ee
.... lots of output here ....
RMAN>
Starting restore at 12-AUG-20
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=621 device type=DISK
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 /opt/oracle/oradata/ORCLCDB/system01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /opt/oracle/oradata/ORCLCDB/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /opt/oracle/oradata/ORCLCDB/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00007 to /opt/oracle/oradata/ORCLCDB/users01.dbf
channel ORA_DISK_1: reading from backup piece /opt/oracle/scripts/setup/01v7mglm_1_1
..........
Number of Cpus = 8
Database Name = ORCLCDB
DataBase Version = 12.2.0.1.0
catcon::set_log_file_base_path: ALL catcon-related output will be written to [/opt/oracle/product/19c/dbhome_1/cfgtoollogs/ORCLCDB/upgrade20200812170336/catupgrdcdbroot_catcon_418.lst]
..........
Grand Total Upgrade Time: [0d:1h:11m:17s]
SQL*Plus: Release 19.0.0.0.0 - Production on Wed Aug 12 18:15:15 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.SQL> Connected.
SQL> Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> ORACLE instance started.
Total System Global Area 1610610568 bytes
Fixed Size 9136008 bytes
Variable Size 654311424 bytes
Database Buffers 939524096 bytes
Redo Buffers 7639040 bytes
Database mounted.
Database opened.
................
The Oracle base remains unchanged with value /opt/oracle
#########################
DATABASE IS READY TO USE!
#########################

And that's all you already have an up and running a 12c RDBMS migrated to 19c version!!! If your DB is restored and migrated successful /tmp/setup directory could be deleted after you stop your migrated DB.

Note: Above process was already tested also with 18c database and if you put a 19c full backup above script just ignore the upgrade process.

--

--