Home / OCI

OCIHow-toIntermediate

OCI File Storage snapshots: schedule them, restore deleted files and recover with a clone

Attach a snapshot policy to an OCI file system, copy deleted files back from .snapshot, and use a clone when the whole file system needs to be recovered.

Deepak Bhardwaj7 min read

Applies toOCI File Storage (NFSv3), OCI CLI, Linux NFS clients

Someone deleted a directory on an OCI File Storage share, or a deployment overwrote it. If a snapshot exists, you can copy the files back from the NFS client in minutes. If none exists, File Storage has nothing to copy from, so set up the schedule below before you need it.

Goal

Get files back with as little disruption as possible, then make sure every production file system has scheduled snapshots.

Situation Use
A few files or one directory lost Copy from .snapshot on a client
Large part of the file system damaged Clone the snapshot, verify, then repoint clients
You need to inspect old data without touching production Clone the snapshot and export it separately
About to run a risky change Take a manual snapshot first
File system deleted, or region unavailable Snapshots won't help; use replication or another copy

Caution

Snapshots live inside the file system. They protect against deleted and overwritten files, not against losing the file system. Keep a separate copy of data you can't lose.

Checks: what snapshots do you have?

Set the OCIDs once:

FS_OCID="ocid1.filesystem.oc1..."
COMPARTMENT_OCID="ocid1.compartment.oc1..."
AD="xxxx:REGION-AD-1"

oci fs file-system get --file-system-id "$FS_OCID" \
  --query 'data."filesystem-snapshot-policy-id"' --raw-output

oci fs snapshot list --file-system-id "$FS_OCID" --lifecycle-state ACTIVE --all \
  --query 'data[].{name:name,created:"time-created",expires:"expiration-time",id:id}' \
  --output table

An empty policy ID means nothing is creating snapshots on a schedule. A policy with no schedules creates none either.

Warning

Check the expires column before doing anything else during an incident. Policy snapshots are deleted when their retention ends, which may be before you finish.

If the snapshot you need expires soon, extend it. This affects that snapshot only, not the policy:

oci fs snapshot update --snapshot-id "$SNAPSHOT_OCID" \
  --expiration-time "2026-12-31T00:00:00Z"

Restore files from .snapshot

Snapshots appear under the hidden .snapshot directory at the root of the file system. It may not show up in a listing of the parent, so name it directly:

ls /mnt/app/.snapshot/
ls -l /mnt/app/.snapshot/SNAPSHOT_NAME/reports/

If the directory isn't there, check the mount. A client that mounts a subdirectory of the export won't see the file system root. Mount the export itself somewhere temporary:

findmnt -t nfs
sudo mkdir -p /mnt/fsroot
sudo mount -t nfs -o vers=3 MOUNT_TARGET_IP:/EXPORT_PATH /mnt/fsroot
ls /mnt/fsroot/.snapshot/

1. Stop writers and save the current state

Pause the process that is deleting or overwriting data. Then take a snapshot so the damaged state can still be examined:

oci fs snapshot create --file-system-id "$FS_OCID" \
  --name "before-restore-$(date -u +%Y%m%d%H%M)" \
  --expiration-time "2026-12-09T00:00:00Z" \
  --wait-for-state ACTIVE

2. Compare before copying

SNAP=/mnt/app/.snapshot/SNAPSHOT_NAME
sudo rsync -aHn --itemize-changes "$SNAP/reports/" /mnt/app/reports/

-n makes this a dry run. Lines starting with >f+++++++++ are files missing from the live directory. Other >f lines are live files that the copy would replace.

3. Copy the data back

To bring back only missing files and leave existing ones alone:

sudo rsync -aH --ignore-existing "$SNAP/reports/" /mnt/app/reports/

To also replace changed files, keep the current versions in a side directory:

sudo rsync -aH --backup --backup-dir=/mnt/app/restore-replaced \
  "$SNAP/reports/" /mnt/app/reports/

Caution

Don't add --delete to a restore unless you have decided that every file created since the snapshot can be lost.

4. Verify

sudo rsync -aHn --checksum --itemize-changes "$SNAP/reports/" /mnt/app/reports/
sudo ls -ln /mnt/app/reports | head

After a full restore, the dry run should list nothing. With --ignore-existing, it still lists files that you chose not to replace.

If owners come back wrong, check the export options. With root squash, root on the client is mapped to another UID and can't set ownership. Run the restore from a trusted admin host whose export option doesn't squash root.

Recover a whole file system with a clone

For large-scale damage, a clone is usable immediately, so you don't wait for a full copy. It is created in the same availability domain as the parent.

CLONE_OCID=$(oci fs file-system create \
  --availability-domain "$AD" --compartment-id "$COMPARTMENT_OCID" \
  --source-snapshot-id "$SNAPSHOT_OCID" \
  --display-name app-restore-clone \
  --wait-for-state ACTIVE --query 'data.id' --raw-output)

EXPORT_SET=$(oci fs mount-target get --mount-target-id "$MT_OCID" \
  --query 'data."export-set-id"' --raw-output)

oci fs export create --file-system-id "$CLONE_OCID" \
  --export-set-id "$EXPORT_SET" --path /app-restore

Mount it read-only and check the data:

sudo mkdir -p /mnt/restore
sudo mount -t nfs -o vers=3,ro MOUNT_TARGET_IP:/app-restore /mnt/restore

If it's good, either copy back what you need or stop the application, unmount, and mount the clone in place of the original. Update /etc/fstab or the OKE persistent volume at the same time.

Before production uses the clone, note that:

  • Exports, tags and encryption key settings are not inherited. Set them again, and add the snapshot policy.
  • Recreate the original's export options; the default export is usually more open than you want.
  • An attached clone still shares data with the parent. You can't delete the root of a clone tree until its clones are deleted or detached.
  • Cloning needs manage on file-systems; use isn't enough.

Schedule snapshots with a policy

Create a policy in the same availability domain as the file system. Retention is in seconds: 86400 is one day, 1209600 is 14 days, 4838400 is eight weeks.

cat > schedules.json <<'EOF'
[
  {"period": "HOURLY", "timeZone": "UTC", "retentionDurationInSeconds": 86400},
  {"period": "DAILY", "timeZone": "UTC", "hourOfDay": 1, "retentionDurationInSeconds": 1209600},
  {"period": "WEEKLY", "timeZone": "UTC", "dayOfWeek": "SUNDAY", "hourOfDay": 3, "retentionDurationInSeconds": 4838400}
]
EOF

POLICY_OCID=$(oci fs filesystem-snapshot-policy create \
  --availability-domain "$AD" --compartment-id "$COMPARTMENT_OCID" \
  --display-name prod-nfs --policy-prefix prod \
  --schedules file://schedules.json \
  --wait-for-state ACTIVE --query 'data.id' --raw-output)

oci fs file-system update --file-system-id "$FS_OCID" \
  --filesystem-snapshot-policy-id "$POLICY_OCID"

Set retention explicitly rather than relying on defaults. Only one hourly schedule is allowed per policy. If two schedules fire at the same time, only the one with the longer retention is kept, so stagger the hours. Start times aren't guaranteed to the minute.

Common problems

Symptom Cause Fix
No .snapshot on the client Mounted below the file system root Mount the export that maps to the root
Policy attached, no snapshots No schedules, or first run not due Check the policy's schedules and wait for the next slot
Space not freed after deleting files Snapshots still hold the blocks Wait for expiry or delete old snapshots
Snapshot stuck in DELETING A clone of it is still hydrating Wait for hydration to finish
Can't delete or change a snapshot Resource lock Check locks with the owner before overriding
NotAuthorizedOrNotFound on clone Only use file-systems granted Grant manage in that compartment

Warning

Changing a file system's snapshot policy or deleting snapshots removes recovery points. Confirm with the data owner, and never do it to free space in the middle of an incident.

Prevent it next time

  • Report file systems with no policy each week, for every availability domain:
oci fs file-system list --compartment-id "$COMPARTMENT_OCID" \
  --availability-domain "$AD" --all \
  --query 'data[?"filesystem-snapshot-policy-id"==`null`].{name:"display-name",id:id}' \
  --output table
  • Take a manual snapshot with an expiration time before deployments and bulk deletes.
  • For databases or applications with open files, quiesce writes first; a snapshot only contains what the server has received.
  • Test one file restore and one clone each quarter, and record how long they take.
  • Add cross-region replication for file systems that must survive a regional failure, and consider snapshot locks for compliance data.