bseltz-cohesity / scripts

Cohesity REST API examples in PowerShell and Python
Apache License 2.0
102 stars 41 forks source link

instantVolumemount.py can't specify which date to restore #77

Closed dragongeek closed 2 years ago

dragongeek commented 2 years ago

I don't see the option to specify a previous date to restore in instantVolumeMount.py. Is that not in the API, or did I miss something? Sometimes one backup takes more than 24 hours, and then the IVM gets out of time from the backup when the next days' runs and completes before the prior.

bseltz-cohesity commented 2 years ago

Hi @dragongeek I have updated the script with the following parameters to view and select the restore point. Let me know if that helps. https://github.com/bseltz-cohesity/scripts/tree/master/python/instantVolumeMount -l, --showversions: show available versions -start, --start: show versions after date -end, --end: show versions before date -r, --runid: use specific run ID

dragongeek commented 2 years ago

If it matters, I have both Python 2.7.5 and 3.6.8, but python defaults to version 2. I can get the -l and --start and to work, but -t, -e, --end and --runid give the errors below: [root@radar python]# instantVolumeMount.py -v liscohobkup -u apiuser -d local -s nuka02 --end "2022-08-23 23:00:03" Connected! [root@radar python]# instantVolumeMount.py -v liscohobkup -u apiuser -d local -s nuka02 --start "2022-08-23 23:00:03" Connected! runId runDate


2207351 2022-08-25 23:00:03 2206901 2022-08-25 16:15:03 2205960 2022-08-24 23:00:03 2205507 2022-08-24 16:15:02 2205369 2022-08-24 15:49:03 2205346 2022-08-24 15:29:03 2205210 2022-08-24 10:44:04 2204937 2022-08-24 04:10:01 [root@radar python]# instantVolumeMount.py -v liscohobkup -u apiuser -d local -s nuka02 -t "2022-08-23 23:00:03" Connected! target server %s not found [root@radar python]# instantVolumeMount.py -v liscohobkup -u apiuser -d local -s nuka02 -e "2022-08-23 23:00:03" usage: instantVolumeMount.py [-h] [-v VIP] [-u USERNAME] [-d DOMAIN] [-c CLUSTERNAME] [-mcm] [-i] [-pwd PASSWORD] [-m MFACODE] [-e] -s SOURCESERVER [-t TARGETSERVER] [-n TARGETUSERNAME] [-p TARGETPASSWORD] [-a] [-vol VOLUME] [-l] [-start START] [-end END] [-r RUNID] instantVolumeMount.py: error: unrecognized arguments: 2022-08-23 23:00:03 [root@radar python]# [root@radar python]# instantVolumeMount.py -v liscohobkup -u apiuser -d local -s nuka02 -n nuka02 --showversions Connected! runId runDate


2207351 2022-08-25 23:00:03 2206901 2022-08-25 16:15:03 2205960 2022-08-24 23:00:03 2205507 2022-08-24 16:15:02 2205369 2022-08-24 15:49:03 [ Truncated for brevity ] 2064510 2022-05-12 23:00:02 2063051 2022-05-11 23:00:03 2054749 2022-05-05 23:00:02 2053339 2022-05-04 23:00:04

From the code, it looks like -e and -t are already defined for other purposes.

[root@radar python]# instantVolumeMount.py -v liscohobkup -u apiuser -d local -s nuka02 --runid 2204937 Connected! mounting volumes to nuka02... InvalidRequest: The specified credentials are not valid Traceback (most recent call last): File "/root/cohesity/bseltzer/bseltzer-scripts/python/bin/instantVolumeMount.py", line 170, in taskid = result['restoreTask']['performRestoreTaskState']['base']['taskId'] KeyError: 'restoreTask' [root@radar python]#

bseltz-cohesity commented 2 years ago

I have updated the readme to correct the parameters, and I also updated the script to fix some issues. Please get the latest here: https://github.com/bseltz-cohesity/scripts/tree/master/python/instantVolumeMount -l, --showversions: show available versions -start, --start: show versions after date -end, --end: show versions before date -r, --runid: use specific run ID

dragongeek commented 2 years ago

It still doesn't seem to work for me. If there's anything you need which I didn't include below, please let me know. And to be clear, I used the curl commands to download the code again, (after renaming the old version with a suffix), and you can see the directory listings below. I also verified they have the Unix line endings (I've been tripped by that one with Git before - LOL!)

@.** bin]# ls -ltr instant pyhes* -rwxr-xr-x. 1 root root 1011 Jan 29 2021 instantVolumeMountDestroy.py-SAVE -rw-r--r--. 1 root root 16373 Jan 29 2021 pyhesity.py-SAVE -rwxr-xr-x. 1 root root 5159 Feb 1 2021 instantVolumeMount.py-SAVE -rw-r--r--. 1 root root 92031 Aug 26 10:21 pyhesity-debug.log -rwxr-xr-x. 1 root root 8223 Aug 30 16:02 instantVolumeMount.py -rwxr-xr-x. 1 root root 2188 Aug 30 16:02 instantVolumeMountDestroy.py -rwxr-xr-x. 1 root root 28803 Aug 30 16:02 pyhesity.py -rw-r--r--. 1 root root 18526 Aug 30 16:07 pyhesity.pyc

The "-l" works, so I listed the dates to use in the start and end testing...

@.*** bin]# instantVolumeMount.py -v liscohobkup -u apiuser -d local -s nuka02 -l Connected!

 runId  runDate
 -----  -------

2212888 2022-08-29 23:00:05 2211510 2022-08-28 23:00:03 2210138 2022-08-27 23:00:04 2208745 2022-08-26 23:00:02 2208167 2022-08-26 15:28:51 [ Truncated for brevity ] 2054749 2022-05-05 23:00:02 2053339 2022-05-04 23:00:04

@. bin]# instantVolumeMount.py -? usage: instantVolumeMount.py [-h] [-v VIP] [-u USERNAME] [-d DOMAIN] [-c CLUSTERNAME] [-mcm] [-i] [-pwd PASSWORD] [-m MFACODE] [-e] -s SOURCESERVER [-t TARGETSERVER] [-n TARGETUSERNAME] [-p TARGETPASSWORD] [-a] [-vol VOLUME] [-l] [-start START] [-end END] [-r RUNID] instantVolumeMount.py: error: argument -s/--sourceserver is required @. bin]# instantVolumeMount.py -v liscohobkup -u apiuser -d local -s nuka02 -start "2022-08-25 23:00:03" -end "2022-08-26 23:00:02" Connected! mounting volumes to nuka02... InvalidRequest: The specified credentials are not valid Traceback (most recent call last): File "/root/cohesity/bin/instantVolumeMount.py", line 186, in taskid = result['restoreTask']['performRestoreTaskState']['base']['taskId'] KeyError: 'restoreTask' @. bin]# instantVolumeMount.py -v liscohobkup -u apiuser -d local -s nuka02 -start "2022-08-25 23:00:03" Connected! mounting volumes to nuka02... InvalidRequest: The specified credentials are not valid Traceback (most recent call last): File "/root/cohesity/bin/instantVolumeMount.py", line 186, in taskid = result['restoreTask']['performRestoreTaskState']['base']['taskId'] KeyError: 'restoreTask' @. bin]# instantVolumeMount.py -v liscohobkup -u apiuser -d local -s nuka02 -end "2022-08-26 23:00:02" Connected! mounting volumes to nuka02... InvalidRequest: The specified credentials are not valid Traceback (most recent call last): File "/root/cohesity/bin/instantVolumeMount.py", line 186, in taskid = result['restoreTask']['performRestoreTaskState']['base']['taskId'] KeyError: 'restoreTask'

And to be sure, I listed where my working directory is, and which to show this is the code I'm executing. @. bin]# pwd /root/cohesity/bin @. bin]# which instantVolumeMount.py /root/cohesity/bin/instantVolumeMount.py

Michael Randall

On Sat, Aug 27, 2022 at 3:12 AM Brian Seltzer @.***> wrote:

I have updated the readme to correct the parameters, and I also updated the script to fix some issues. Please get the latest here: https://github.com/bseltz-cohesity/scripts/tree/master/python/instantVolumeMount -l, --showversions: show available versions -start, --start: show versions after date -end, --end: show versions before date -r, --runid: use specific run ID

— Reply to this email directly, view it on GitHub https://github.com/bseltz-cohesity/scripts/issues/77#issuecomment-1229164523, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5SLXCYAH5V4GNKB4WNQNDV3HSZ5ANCNFSM57JGTWXQ . You are receiving this because you were mentioned.Message ID: @.***>

bseltz-cohesity commented 2 years ago

Just like in the UI, guest credentials are required when performing instant volume mount on a VM. The credentials can be omitted for physical servers that have the agent installed.

dragongeek commented 2 years ago

It has the credentials stored using your mechanism already. It is running backups from here every night. This works with the same credentials!

@. bin]# ./instantVolumeMount.py -v liscohobkup -u apiuser -d local -s nuka02 -t nuka02 -a -m /local Connected! mounting volumes to nuka02... Volume mount ended with status kSuccess Task ID for tearDown is: 2213862 /uvinstance mounted to /opt/cohesity/mount_paths/vol_mounts/1661906218002500_task2213862_1_agent_vmfs_vmfs /kiska_ssa mounted to /opt/cohesity/mount_paths/vol_mounts/1661906219054782_task2213862_1_agent_vmfs_vmfs lvol_1 mounted to /opt/cohesity/mount_paths/vol_mounts/1661906220292117_task2213862_1_agent_vmfs__0_vmfs / mounted to /opt/cohesity/mount_paths/vol_mounts/1661906221971123_task2213862_1_agent_vmfs_vmfs /boot mounted to /opt/cohesity/mount_paths/vol_mounts/1661906222250745_task2213862_1_agent_vmfs_0x000cebe3_1_vmfs /u0 mounted to /opt/cohesity/mount_paths/vol_mounts/1661906222354180_task2213862_1_agent_vmfs_vmfs /local mounted to /opt/cohesity/mount_paths/vol_mounts/1661906223168063_task2213862_1_agent_vmfs_vmfs @. bin]#

Michael Randall

On Tue, Aug 30, 2022 at 5:26 PM Brian Seltzer @.***> wrote:

Just like in the UI, guest credentials are required when performing instant volume mount on a VM. The credentials can be omitted for physical servers that have the agent installed.

— Reply to this email directly, view it on GitHub https://github.com/bseltz-cohesity/scripts/issues/77#issuecomment-1232307733, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5SLXGRJYD3ILNBSAUEVXLV32RCBANCNFSM57JGTWXQ . You are receiving this because you were mentioned.Message ID: @.***>

bseltz-cohesity commented 2 years ago

No I'm referring to the [-n TARGETUSERNAME] [-p TARGETPASSWORD] parameters to authenticate to the VM during the volume mount. These are required when mounting to a VM

dragongeek commented 2 years ago

Oh, Sorry about that. I missed the '-a' needed to specify the already configured Agent! Some days I can't get enough caffeine in my system to cover for my distracted brain. >_<

Thanks so much for your help. I've told my management how wonderfully responsive you've been. Now I get to tell them I was blind in my hurry. (That's ok, we're all overworked here so they'll forgive me.)

Michael Randall

On Tue, Aug 30, 2022 at 5:41 PM Brian Seltzer @.***> wrote:

No I'm referring to the [-n TARGETUSERNAME] [-p TARGETPASSWORD] parameters to authenticate to the VM during the volume mount. These are required when mounting to a VM

— Reply to this email directly, view it on GitHub https://github.com/bseltz-cohesity/scripts/issues/77#issuecomment-1232316731, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5SLXCSZ2FJTNUXPFA6CL3V32SZ5ANCNFSM57JGTWXQ . You are receiving this because you were mentioned.Message ID: @.***>

bseltz-cohesity commented 2 years ago

Ah great. Glad you got it working!

dragongeek commented 2 years ago

OH, I was poking more and found that if I add the -l then start and end options, it lists the range. I'm used to seeing an extra pair of braces around a required option group, e.g. instantVolumeMount.py ... [ -l [ -start START ] [ -end END ] ]

Now how about the runid option? Did I miss something with it? It should be using the stored credentials which I've been running with for a few months now.

@. bin]# instantVolumeMount.py -v liscohobkup -u apiuser -d local -s nuka02 -r 2204937 Connected! mounting volumes to nuka02... InvalidRequest: The specified credentials are not valid Traceback (most recent call last): File "/root/cohesity/bin/instantVolumeMount.py", line 186, in taskid = result['restoreTask']['performRestoreTaskState']['base']['taskId'] KeyError: 'restoreTask' @. bin]#

Michael Randall

On Sat, Aug 27, 2022 at 3:12 AM Brian Seltzer @.***> wrote:

I have updated the readme to correct the parameters, and I also updated the script to fix some issues. Please get the latest here: https://github.com/bseltz-cohesity/scripts/tree/master/python/instantVolumeMount -l, --showversions: show available versions -start, --start: show versions after date -end, --end: show versions before date -r, --runid: use specific run ID

— Reply to this email directly, view it on GitHub https://github.com/bseltz-cohesity/scripts/issues/77#issuecomment-1229164523, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5SLXCYAH5V4GNKB4WNQNDV3HSZ5ANCNFSM57JGTWXQ . You are receiving this because you were mentioned.Message ID: @.***>

bseltz-cohesity commented 2 years ago

Remember you either have to use -a, or use -n and -p -n, --targetusername: (optional) only required if agent is not already installed (VM) -p, --targetpassword: (optional) only required if agent is not already installed (VM) -a, --useexistingagent: (optional) use existing agent during mount to a VM