Clones are the fastest way to give test, reporting or forensics a copy of production disks. A clone is usable within seconds, while a backup restore pulls data from Object Storage first. But a clone has its own rules: it can't leave the availability domain, it's only consistent per volume unless you clone a group, and a cloned filesystem keeps the source's UUIDs. This sheet covers the commands and the failure modes.
Clone, backup or replica?
| Need | Use | Why |
|---|---|---|
| Copy in the same AD within minutes | Clone (--source-volume-id) | Direct disk-to-disk copy, attachable when AVAILABLE |
| Copy in a different AD or region | Backup + restore, or block volume replication | Clones are limited to the same region, AD and tenancy |
| Several volumes consistent with each other (data + redo + logs) | Volume group clone | Point-in-time and crash-consistent across the group |
| Copy you keep for weeks for audit or rollback | Backup | Clones are billed as full volumes, backups as Object Storage |
| Repair a broken boot disk | Boot volume clone attached to a rescue VM | You never touch the original |
Tip
To refresh into another AD, take a volume or volume group backup and restore it with
--availability-domainset to the target AD. If you have cross-AD replication, activate a replica instead. Don't plan a design around cross-AD clones.
Single volume clone
SRC=ocid1.volume.oc1..prod-data
AD=$(oci bv volume get --volume-id "$SRC" --query 'data."availability-domain"' --raw-output)
COMP=ocid1.compartment.oc1..test
oci bv volume create \
--source-volume-id "$SRC" \
--availability-domain "$AD" \
--compartment-id "$COMP" \
--display-name "test-data-$(date +%Y%m%d)" \
--size-in-gbs 1024 \
--vpus-per-gb 10 \
--freeform-tags '{"purpose":"refresh","clone-of":"prod-data"}' \
--wait-for-state AVAILABLE \
--query 'data.id' --raw-output
| Option | Rule |
|---|---|
--size-in-gbs | Same size as the source or larger, never smaller. Grow the partition and filesystem afterwards. |
--vpus-per-gb | 0 (Lower Cost), 10, 20, 30–120. You can also change it after cloning. Test copies rarely need prod's VPUs. |
--kms-key-id | Encrypt the clone with a different Vault key. Use an AES key; RSA keys aren't supported for volume encryption. |
--compartment-id | The clone can go to another compartment, which is useful for isolating test copies under different IAM. |
The background copy
When the state becomes AVAILABLE you can attach and use the clone right away. The data keeps copying in the background, which Oracle says can take up to thirty minutes depending on size. Check whether the copy has finished:
oci bv volume get --volume-id "$CLONE" --query 'data."is-hydrated"'
What this means in practice:
- Don't benchmark a clone until
is-hydratedistrue. I/O results during the copy don't reflect the volume's steady-state performance. - If the source is attached, wait for the first clone to finish before you start another from the same source. If the source is detached, you can create up to ten clones from it at the same time. Check the current limits page if you plan more.
- Script a wait on
is-hydratedbefore you delete the source or start the next clone in a chain.
until [ "$(oci bv volume get --volume-id "$CLONE" --query 'data."is-hydrated"' --raw-output)" = "true" ]; do
sleep 30
done
Volume group clone (multi-volume consistency)
A database with data files on one volume and redo or WAL on another needs one consistent point across both. Cloning the volumes one by one doesn't give you that. Put them in a volume group once, then clone the group.
# One-time: group the production volumes (up to 32 volumes; each volume can be in only one group)
oci bv volume-group create --compartment-id "$PRODCOMP" --availability-domain "$AD" \
--display-name prod-db-vg \
--source-details '{"type":"volumeIds","volumeIds":["ocid1.volume.oc1..data","ocid1.volume.oc1..redo"]}' \
--wait-for-state AVAILABLE
# Every refresh: clone the group
oci bv volume-group create --compartment-id "$COMP" --availability-domain "$AD" \
--display-name "test-db-vg-$(date +%Y%m%d)" \
--source-details '{"type":"volumeGroupId","volumeGroupId":"ocid1.volumegroup.oc1..prod-db-vg"}' \
--wait-for-state AVAILABLE \
--query 'data."volume-ids"'
The clone is a new group with new volumes. The source and the clone share nothing. Deleting a volume group doesn't delete its volumes, so clean up both:
for V in $(oci bv volume-group get --volume-group-id "$VG" --query 'data."volume-ids"[]' --raw-output); do
echo "$V"
done
oci bv volume-group delete --volume-group-id "$VG" --force
# then oci bv volume delete --volume-id <each> --force
Warning
Crash-consistent means it looks like the power was pulled. Databases recover from that the way they do after a crash, but only if every file the database needs is in the group. A control file, archive log directory or tablespace left on an ungrouped volume produces a clone that won't open, or opens with missing data. List the database's files against the group's volumes before you trust it.
For a single-volume, application-consistent copy, freeze the filesystem around the clone call. The clone takes its point in time when the request is accepted, so the freeze lasts seconds:
sudo fsfreeze -f /u01/data
oci bv volume create --source-volume-id "$SRC" --availability-domain "$AD" --compartment-id "$COMP" --wait-for-state PROVISIONING
sudo fsfreeze -u /u01/data
Put fsfreeze -u in a trap so a failed CLI call can't leave production frozen.
Boot volume clone
oci bv boot-volume create \
--source-boot-volume-id ocid1.bootvolume.oc1..prod-web \
--display-name prod-web-boot-forensics \
--wait-for-state AVAILABLE
The clone is created in the source's AD and, by default, the source's compartment. You can attach it as a data volume to a rescue instance, or launch a new instance from it with oci compute instance launch --source-boot-volume-id. Boot volume VPUs are 10, 20 or 30–120 (no 0).
Attach and mount: the duplicate-ID traps
oci compute volume-attachment attach --instance-id "$INST" --volume-id "$CLONE" \
--type paravirtualized --wait-for-state ATTACHED
A clone is byte-for-byte the same as its source, including filesystem UUIDs and LVM IDs. If the clone and the source (or another clone of it) end up on the same host, these errors show up:
| Symptom | Cause | Fix |
|---|---|---|
mount: wrong fs type / dmesg Filesystem has duplicate UUID ... can't mount (XFS) | Same XFS UUID already mounted | One-off: mount -o nouuid /dev/sdc1 /mnt/clone. Permanent: unmount, then xfs_admin -U generate /dev/sdc1 |
fstab UUID= mounts the wrong disk at boot | ext4 or XFS UUIDs are the same on both | ext4: tune2fs -U random /dev/sdc1. Update fstab to the new UUID |
WARNING: Not using device ... duplicate PV and the VG is unusable | Same LVM PV and VG UUIDs | vgimportclone --basevgname vg_clone /dev/sdc (renames VG, regenerates UUIDs) |
| Oracle ASM sees two disks with the same header | ASM disk labels cloned | Never present a clone to the source's ASM instance. Mount it on a separate host |
Boot clone attached to a rescue VM built from the same image won't mount / | Same root XFS UUID as the rescue VM's own root | mount -o nouuid |
Caution
Run
xfs_admin -U,tune2fs -Uandvgimportcloneagainst the clone's device only. Check the device withlsblk -o NAME,SIZE,SERIAL,UUID,MOUNTPOINTand confirm it isn't mounted. Compare the device path with the attachment fromoci compute volume-attachment get. Rewriting the UUID on the production disk breaks its fstab entry on the next boot.
Environment refresh skeleton
# 1. detach and delete last week's clone (on the test instance: umount first)
oci compute volume-attachment detach --volume-attachment-id "$OLD_ATT" --force --wait-for-state DETACHED
oci bv volume delete --volume-id "$OLD_CLONE" --force --wait-for-state TERMINATED
# 2. clone, 3. wait for is-hydrated if you'll benchmark, 4. attach, 5. fix UUIDs if needed, 6. mask data
Step 6 matters. A clone of production carries production's personal data, credentials and connection strings into a test compartment. Run your masking or credential-reset job before you give testers access.
Prevent surprises next time
- Tag every clone (
purpose=refresh,clone-of=...) and find the leftovers each week:oci search resource structured-search --query-text "query volume resources where (freeformTags.key = 'purpose' && freeformTags.value = 'refresh')" - Put multi-volume databases in a volume group at build time, not on the day you need a consistent clone.
- Set fstab entries on test hosts with
nofailso a missing or renamed clone doesn't put the host into emergency mode. - Keep clone VPUs low for test copies and raise them only for performance tests, after
is-hydratedis true. - Write down that clones stay in their AD. Anyone who needs a copy elsewhere uses backups or replication, so there are no surprises during a DR exercise.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get