101 Series of Oracle in Google Cloud – Part III : Using Google Cloud Platform Snapshots to Clone a DB in a VM
Continuing on the GCP 101 series. I will explain how is it that you use GCP (Google Cloud Platform) Disk Snapshots to clone Database in a GCP VM (Virtual Machines).
I again want to mention that first check with Oracle and your licensing rep on what is supported and licensing before doing any of this work.
I have 2 VMs that I built using the steps in my post 101 SERIES OF ORACLE IN GOOGLE CLOUD – PART I : BUILDING ASM AND DATABASE
rene@renes-imac ~ % gcloud compute instances list | grep rene
rene-ace-test-inst1 us-central1-c n1-standard-8 ***.***.0.2 ***.***.***.134 RUNNING
rene-ace-test-inst2 us-central1-c n1-standard-8 ***.***.0.3 ***.***.***.64 RUNNING
In the first VM what I will do is create a table marker with the time close enough to the snapshot that I will take
[oracle@rene-ace-test-inst1 ~]$ echo "
CREATE TABLE system.snapshot_marker (instance_name VARCHAR2(16), host_name VARCHAR2(64), job_time TIMESTAMP);
DELETE FROM system.snapshot_marker;
INSERT INTO system.snapshot_marker SELECT instance_name, host_name, systimestamp FROM v\$instance;
SELECT * FROM system.snapshot_marker;
" | sqlplus -s / as sysdba
Table created.
0 rows deleted.
1 row created.
INSTANCE_NAME
----------------
HOST_NAME
----------------------------------------------------------------
JOB_TIME
---------------------------------------------------------------------------
DBTEST
rene-ace-test-inst1
14-APR-21 19.18.19.530694 PM
Once I create the marker in the database in rene-ace-test-inst1, I will take a snapshot of the disk that contains the DATA DG which is where the files of DBTEST reside.
Rene@eclipsyss-mbp ~ % gcloud compute disks snapshot rene-ace-disk-asm1 \
--snapshot-names=rene-ace-disk-snap-asm1
Creating snapshot(s) rene-ace-disk-snap-asm1...done.
Rene@eclipsyss-mbp ~ % gcloud compute snapshots list \
--filter="name=('rene-ace-disk-snap-asm1')"
NAME DISK_SIZE_GB SRC_DISK STATUS
rene-ace-disk-snap-asm1 150 us-central1-c/disks/rene-ace-disk-asm1 READY
On rene-ace-test-inst2, which is currently running also a DB that I previously cloned also called DBTEST, I will stop the database and dismount the DATA DG
[oracle@rene-ace-test-inst2 ~]$ ${HOME}/working/crs_status.sh
Name Target State Server State details
------------------------------------------------------------------------------------------------------------------------
ora.DATA.dg ONLINE ONLINE rene-ace-test-inst2 STABLE
ora.LISTENER.lsnr ONLINE ONLINE rene-ace-test-inst2 STABLE
ora.asm ONLINE ONLINE rene-ace-test-inst2 Started,STABLE
ora.ons OFFLINE OFFLINE rene-ace-test-inst2 STABLE
ora.cssd ONLINE ONLINE rene-ace-test-inst2 STABLE
ora.dbtest.db ONLINE ONLINE rene-ace-test-inst2 Open,HOME=/u01/app/o
ora.diskmon OFFLINE OFFLINE STABLE
ora.evmd ONLINE ONLINE rene-ace-test-inst2 STABLE
[oracle@rene-ace-test-inst2 ~]$ . oraenv
ORACLE_SID = [ORCL] ? DBTEST
The Oracle base remains unchanged with value /u01/app/oracle
[oracle@rene-ace-test-inst2 ~]$ srvctl stop database -d ${ORACLE_SID} -o abort
[oracle@rene-ace-test-inst2 ~]$ asmcmd lsdg
State Type Rebal Sector Logical_Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
MOUNTED EXTERN N 512 512 4096 1048576 102399 98440 0 98440 0 N DATA/
[oracle@rene-ace-test-inst2 ~]$ echo "ALTER diskgroup DATA DISMOUNT;" | sqlplus -s / as sysasm
Diskgroup altered.
Once I dismount the DATA DG, what I will now detach the current disk which the DATA DG uses and delete it
rene@renes-imac ~ % gcloud compute instances detach-disk rene-ace-test-inst2 \
--disk=rene-ace-2-disk-asm1 \
--zone=us-central1-c
Updated [https://www.googleapis.com/compute/v1/projects/eclipsys/zones/us-central1-c/instances/rene-ace-test-inst2].
rene@renes-imac ~ % gcloud compute disks delete rene-ace-2-disk-asm1 \
--zone=us-central1-c
The following disks will be deleted:
- [rene-ace-2-disk-asm1] in [us-central1-c]
Do you want to continue (Y/n)? y
Deleted [https://www.googleapis.com/compute/v1/projects/eclipsys/zones/us-central1-c/disks/rene-ace-2-disk-asm1]
What I will do now is create an SSD Persistent disk based on the snapshot I created earlier
rene@renes-imac ~ % gcloud compute disks create rene-ace-2-disk-asm1 \
--type=pd-ssd \
--zone=us-central1-c \
--source-snapshot=rene-ace-disk-snap-asm1
Created [https://www.googleapis.com/compute/v1/projects/eclipsys/zones/us-central1-c/disks/rene-ace-2-disk-asm1].
NAME ZONE SIZE_GB TYPE STATUS
rene-ace-2-disk-asm1 us-central1-c 150 pd-ssd READY
rene@renes-imac ~ % gcloud compute instances attach-disk rene-ace-test-inst2 \
--disk=rene-ace-2-disk-asm1 \
--device-name=rene-ace-2-disk-asm1 \
--mode=rw \
--zone=us-central1-c
Updated [https://www.googleapis.com/compute/v1/projects/eclipsys/zones/us-central1-c/instances/rene-ace-test-inst2].
Now, the only thing that I need to do is to make sure that the disk I created is present in the UDEV rules and reload the rules
[root@rene-ace-test-inst2 ~]# /usr/lib/udev/scsi_id -g -u -d /dev/sdb
0Google_PersistentDisk_rene-ace-2-disk-asm1
[root@rene-ace-test-inst2 ~]# vi /etc/udev/rules.d/99-oracle-asmdevices.rules
[root@rene-ace-test-inst2 ~]# cat /etc/udev/rules.d/99-oracle-asmdevices.rules
KERNEL=="sd?1", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/$parent", RESULT=="0Google_PersistentDisk_rene-ace-2-disk-asm1", SYMLINK+="oracleasm/asm-disk1", OWNER="oracle", GROUP="dba", MODE="0660"
[root@rene-ace-test-inst2 ~]# /sbin/partprobe /dev/sdb1
[root@rene-ace-test-inst2 ~]# /sbin/udevadm control --reload-rules
[root@rene-ace-test-inst2 ~]# /sbin/partprobe /dev/sdb1
[root@rene-ace-test-inst2 ~]# /sbin/udevadm control --reload-rules
[root@rene-ace-test-inst2 ~]# ls -al /dev/oracleasm/*
lrwxrwxrwx. 1 root root 7 Apr 15 00:55 /dev/oracleasm/asm-disk1 -> ../sdb1
Now that the disk that I created from the snapshot is ready, I will now mount it in ASM
[oracle@rene-ace-test-inst2 ~]$ export ORAENV_ASK=NO
[oracle@rene-ace-test-inst2 ~]$ export ORACLE_SID=+ASM
[oracle@rene-ace-test-inst2 ~]$ . oraenv
The Oracle base remains unchanged with value /u01/app/oracle
[oracle@rene-ace-test-inst2 ~]$ echo "ALTER diskgroup DATA MOUNT;" | sqlplus -s / as sysasm
Diskgroup altered.
The only thing pending is to bring up the DBTEST and verify that the data is present from the system.snapshot_marker table that I created at the beginning
[oracle@rene-ace-test-inst2 ~]$ export ORAENV_ASK=NO
[oracle@rene-ace-test-inst2 ~]$ export ORACLE_SID=DBTEST
[oracle@rene-ace-test-inst2 ~]$ . oraenv
The Oracle base remains unchanged with value /u01/app/oracle
[oracle@rene-ace-test-inst2 ~]$ srvctl start database -d ${ORACLE_SID}
[oracle@rene-ace-test-inst2 ~]$ echo "
> SELECT instance_name, host_name, systimestamp FROM v\$instance;
> SELECT * FROM system.snapshot_marker;
> " | sqlplus -s / as sysdba
INSTANCE_NAME
----------------
HOST_NAME
----------------------------------------------------------------
SYSTIMESTAMP
---------------------------------------------------------------------------
DBTEST
rene-ace-test-inst2
15-APR-21 01.35.02.684737 AM +00:00
INSTANCE_NAME
----------------
HOST_NAME
----------------------------------------------------------------
JOB_TIME
---------------------------------------------------------------------------
DBTEST
rene-ace-test-inst1
14-APR-21 19.18.19.530694 PM
Hope this small blog post will help you understand a little bit better how the snapshots work in GCP and how they can be used if with Oracle in a GCP VM.