#!/bin/bash # fcs_post_archive.bash - Final Cut Server Post Archive 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 from a Script Response, which is triggered from a subscription to an asset # that has an Archive Status of Offline, trigger if changed. # It receives metadata fields related to the just-archived asset from Final Cut Server # and then remotely logs into the facility BakBone NetVault Server and executes # first a nvsetcreate, which defines the path for the single-file backup. It then # executes a nvjobcreate, which defines a job for the backup set and submits it. # Both backup set and backup job are titled using the Final Cut Server Asset ID, for ease in cross-correlation. # This script also creates an output file, located at nvcatalogpath, which records the association between # the archived file's full path and its NetVault Backup Job Title. # usage from the Final Cut Server Script Response: # Command Path: /usr/metamedia/fcs_post_archive.bash # Command Parameters: "[File Name]" "[Stored On]" "[Location]" [Asset ID] # Note: It's crucial to encase the Unicode String fields within hard quotes "" so that spaces and other yucky characters get expanded into this script. # Asset ID is a pure integer, so it doesn't need this protection. # 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 Final Cut Server Archive Path is the full path to the root of the Final Cut Server's Archive Device. fcsarchivepath="/Volumes/XSAN_VOLUME/ARCHIVE/" # 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 Virtual Disk Device Set is created within NVAdmin and specifies the location and settings # for the destination for the archive. nvvddset="MMCT_VDD_DEFAULT" # A NetVault Backup Advanced Options Set is created within NVAdmin and specifies additional advanced options # for the backup job, including data duplication to tape and the lifecycle of the resulting VDD and Tape-based files, # and firing off emails for notification after the job is complete. For this script, it should also contain the triggers # for the nv_jobid.bash and nv_jobstatus.bash scripts that NetVault fires before and after jobs. nvbackupadvoptset="MMCT_ADVOPT_DEFAULT" # variables passed from Final Cut Server filename=$1 storedon=$2 location=$3 assetid=$4 # The storedon variable now needs to be converted into its corresponding deviceid. # The following conditional can be filled with additional elifs to provide a complete statement of all # "archivable" devices in this Final Cut Server deployment, and their corresponding IDs. if [ "$storedon" = "Xsan Volume" ]; then fcsdevid=7 elif [ "$storedon" = "Stock Images" ]; then fcsdevid=8 fi # derived variables nvbackupselectionset="NVBS$assetid" nvbackupjobtitle="NVBJ$assetid" nvpath="$fcsarchivepath$fcsdevid$location/$filename" # Deposit the correlation between file path to NetVault Backup Job Title. echo "$nvpath $nvbackupjobtitle" >> $nvcatalogpath # Create the one-file set for the backup $nvlogin "/usr/netvault/util/nvsetcreate -setname $nvbackupselectionset -type BS -client \""$nvname"\" -plugin \"File System\" -include \""$nvpath"\"" # Create the job and submit it $nvlogin "/usr/netvault/util/nvjobcreate -jobtitle $nvbackupjobtitle -selectionsetname $nvbackupselectionset -targetsetname $nvvddset -advoptssetname $nvbackupadvoptset -submit" # Wait a bit, and then get the Job ID from the just-created Job Title sleep 10 nvjobid=`grep "$nvbackupjobtitle" $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 # Now for the scary part, if we have a successful backup, then we need to delete the file from the Final Cut Server Archive Device. # 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" rm "$nvpath" else exit 1 fi exit 0