#!/bin/bash # fcs_pre_restore.bash - Final Cut Server Pre Restore Script # Written by Matt Geller, Meta Media Creative Technologies # (800) 305-2163 | www.metamediatech.com # Use of this script in total or in part is permitted as long as credit to the author is preserved. # Abstract: # This script fires before a Final Cut Server Restore job. # It receives a single variable from Final Cut Server, which is the full path # of the asset's Archive Copy, or where the archived Primary Representation used to reside, # before it was further archived by NetVault. # It then queries the file located at nvcatalogpath and receives the NetVault Backup Job Title. # It then remotely logs into the facility BakBone NetVault Server and executes # first a nvsetcreate, which defines the previous backup job to be restored. # It then executes a nvjobcreate, which defines a job for the restore set and submits it. # usage from Final Cut Server pre-restore command metadata field: # /usr/metamedia/fcs_pre_restore.bash # Note: No additional varibles are specified, since Final Cut Servers allows none when scripts # are triggered from a Device's pre-restore command. It does pass the asset's Archive Copy path # as $1. # global variables # Note: We are logging into the NetVault Server with RSA-authenticated ssh, # which would need to be setup before secure commands can be executed on this server without requiring a password. nvlogin="ssh root@172.16.1.10" # The NetVault name is the name of your NetVault Server, according to the NVAdmin GUI application. nvname="server1" # The NetVault Catalog Path is the path and file on the Final Cut Server in which we will dump a line # of text to correlate the full path of the file to its NetVault Backup Job Title. # We grep out and use this line of text during restore in order to identify the correct job to specify when requesting a restore of the file. nvcatalogpath="/usr/metamedia/nv_catalog.out" # The NetVault Job ID Path is the path and file on the Final Cut Server in which NetVault will be dumping a line # of text at -job start- which contains the NetVault Job Title and the Job ID that it assigned to the Job. # We can use this to derive the NetVault Job ID for the Job we submit in this script. nvjobidpath="/usr/metamedia/nv_jobid.out" # The NetVault Job Status Path is the path and file on the Final Cut Server in which NetVault will be dumping a line # of text at -job completion- which contains the NetVault Job Title, Job ID and Job Status for a completed Job. # We can use this to determine when the Job is complete and if it was successful. nvjobstatuspath="/usr/metamedia/nv_jobstatus.out" # A NetVault Restore Advanced Options Set is created within NVAdmin and specifies additional advanced options # for the restore job, including firing off emails for notification after the job is complete. nvrestoreadvoptset="MMCT_ADVOPTEML" # variables passed from Final Cut Server nvpath=$1 # derived variables nvbackupjobtitle=`grep "$nvpath" $nvcatalogpath | tail -1 | awk '{ print $NF }'` assetid=`echo $nvbackupjobtitle | sed s/NVBJ//` nvrestoreselectionset=NVRS$assetid nvrestorejobtitle=NVRJ$assetid # Create the selection set for the restore $nvlogin "/usr/netvault/util/nvsetcreate -setname $nvrestoreselectionset -type RS -client \""$nvname"\" -plugin \"File System\" -title $nvbackupjobtitle -include \""$nvpath"\" -restoreoption NVFS_OPT_OVERNEW=FALSE" # Create the job and submit it $nvlogin "/usr/netvault/util/nvjobcreate -jobtitle $nvrestorejobtitle -type restore -selectionsetname $nvrestoreselectionset -advoptssetname $nvrestoreadvoptset -submit" # Wait a bit, and then get the Job ID from the just-created Job Title sleep 10 nvjobid=`grep "$nvrestorejobtitle" $nvjobidpath | tail -1 | awk '{ print $NF }'` # Keep asking nv_jobstatus.out if a report for our job has come over, and if not, wait a little while and ask again. nvstatusresult=`grep " $nvjobid " $nvjobstatuspath` while [ ${#nvstatusresult} = 0 ]; do echo "waiting for job status..." sleep 5 # Now refresh our nvstatusresult nvstatusresult=`grep " $nvjobid " $nvjobstatuspath` done # If we have a successful backup, then we need to end the script and let Final Cut Server pick up its file for restore. # But if we don't, we exit 1 and don't touch the file. if [ `echo $nvstatusresult | awk '{ print $NF }'` = "SUCCEEDED" ]; then echo "Success! $nvstatusresult" else exit 1 fi exit 0