import { switchToClusterFromEnv } from 'src/lib/cluster' ; import { execCmdWithExitOnFailure } from 'src/lib/cmd-utils' ; import { addCeloEnvMiddleware , CeloEnvArgv } from 'src/lib/env-utils' ; import yargs from 'yargs' ; export const command = 'restore' ; export const describe = "command for restoring a miner's persistent volume (PVC) from snapshot" ; interface RestoreArgv extends CeloEnvArgv { minername : string ; snapshotname : string ; } export const builder = ( argv ) => { return addCeloEnvMiddleware ( argv ) . option ( 'minername' , { type : 'string' , description : 'Name of the miner node' , demand : 'Please specify the miner node to restore, eg. gethminer1' , } ) . option ( 'snapshotname' , { type : 'string' , description : 'Name of the snapshot' , demand : 'Name of the snapshot (from gcloud compute snapshots list)' , } ) ; } ; export const handler = async ( argv ) => { await switchToClusterFromEnv ( argv . celoEnv , true , true ) ; const minerName = argv . minername ; const clusterName = 'celo-networks-dev' ; const diskType = 'pd-ssd' ; const namespace = argv . celoEnv ; const pvc = `${ namespace }-${ minerName }-pvc` ; const getPVCNameCommand = `kubectl get persistentvolumeclaim ${ pvc } --namespace ${ namespace } -o=jsonpath={.spec.volumeName}` ; const pvcId = ( await execCmdWithExitOnFailure ( getPVCNameCommand ) ) [ 0 ] ; const pvcFullId = `gke-${ clusterName }--${ pvcId }` ; console . debug ( `PVC name is ${ pvcFullId }` ) ; const restoreSnapshotCmd = `gcloud compute disks create ${ pvcFullId } --source-snapshot=${ argv . snapshotname } --type ${ diskType }` ; await execCmdWithExitOnFailure ( restoreSnapshotCmd ) ; } ;