Creating Oracle ZFS Snapshots using Shell Script

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 create project snapshots using a shell script for both ZFS controllers (in case you are using active/active ZFS cluster).

Creating Project Snapshots

 

> cat snapshotdt_project.sh

#ssh-agent bash

#ssh-add ~/.ssh/id_dsa

{

echo script

echo "{"

echo " run('cd /');"

echo " run('shares');"

echo " run('set pool=pool1');"

echo " run('select H1-dbname');"

dt=`date "+%Y%m%d_%H%M"`;

echo " run('snapshots snapshot snap_$dt');"

echo " printf('snapshot of the project H1-dbname completed..\n');"

echo "}"

echo "exit"

} | ssh -T -i ~/.ssh/id_rsa root@ZFSControler-1

{

echo script

echo "{"

echo " run('cd /');"

echo " run('shares');"

echo " run('set pool=pool2');"

echo " run('select H2-dbname');"

dt=`date "+%Y%m%d_%H%M"`;

echo " run('snapshots snapshot snap_$dt');"

echo " printf('snapshot of the project H2-dbname completed..\n');"

echo "}"

echo "exit"

} | ssh -T -i ~/.ssh/id_rsa root@ ZFSControler-2

Script Output : 

> ./ snapshotdt_project.sh

snapshot of the project H1-dbname completed..

snapshot of the project H2-dbname completed..