Listing Oracle ZFS Appliance Snapshots

The Oracle ZFS Storage Appliance features a snapshot data service, Snapshots are read-only copies of a filesystem at a given point-in-time. You can think of ZFS snapshots as a restore point of data set for project and shares, which can be used to rollback state of data set to point-in-time just like Oracle database restore points conceptually. ZFS Snapshots are only logical entities, so you can create virtually unlimited number of snapshots without taking up any space. Snapshots can be scheduled or taken manually, depending on usage and policies. We can manage snapshots using Oracle ZFS Appliance graphical interface BUI or through scripts. There are times when you want to manage snapshot using scripts especially when you want to integrate them with Oracle backups. SSH user equivalence might be required if you are looking to execute the following script without providing the root passwords. Following is an example, how to list project snapshots using shell a script for both ZFS controllers (in case you are using active/active ZFS cluster).

List Project SnapShots

> cat list_snapshots.sh

echo "Head 1"

cat <<eof |ssh -T -i ~/.ssh/id_rsa root@zfscontroller-1

script

run('shares');

run ('set pool=pool1');

run ('select H1-dbname');

run ('snapshots');

snapshots = list();

for (i = 0; i < snapshots.length; i++) {

  printf("%20s:", snapshots[i]);

  run ('select ' + snapshots[i]);

  printf("%-10s\n", run('get space_data').split(/\s+/)[3]);

  run('cd ..');

}

eof

echo "Head 2"

cat <<eof |ssh -T -i ~/.ssh/id_rsa root@zfscontroller -2

script

run('shares');

run ('set pool=pool2');

run ('select H2-dbhome');

run ('snapshots');

snapshots = list();

for (i = 0; i < snapshots.length; i++) {

  printf("%20s:", snapshots[i]);

  run ('select ' + snapshots[i]);

  printf("%-10s\n", run('get space_data').split(/\s+/)[3]);

  run('cd ..');

}

eof

Script Output:

> ./list_snapshots.sh

Head 1

  snap_20170921_1720:9.17T

  snap_20170924_1938:18.5T

Head 2

  snap_20170921_1720:8.09T

  snap_20170924_1938:16.2T

oracle@exa2node:/home/oracle