MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / runStorageRestore

Function runStorageRestore

internal/cli/storage.go:731–809  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

729}
730
731func runStorageRestore(cmd *cobra.Command, args []string) error {
732 ctx := context.Background()
733 nodeName := args[0]
734 storageName := args[1]
735 volID := args[2]
736
737 vmidStr := args[3]
738 vmid, err := strconv.Atoi(vmidStr)
739 if err != nil {
740 return printError(fmt.Errorf("invalid vmid %q: must be an integer", vmidStr))
741 }
742
743 guestType, _ := cmd.Flags().GetString("type")
744 if guestType == "" {
745 guestType, err = inferGuestTypeFromVolID(volID)
746 if err != nil {
747 return printError(err)
748 }
749 }
750
751 if guestType != "qemu" && guestType != "lxc" {
752 return printError(fmt.Errorf("invalid guest type %q: must be qemu or lxc", guestType))
753 }
754
755 confirmed, _ := cmd.Flags().GetBool("confirm")
756 if !confirmed {
757 fmt.Printf("Dry-run: would restore %s (type: %s) to VMID %d on node %s (storage: %s)\n",
758 volID, guestType, vmid, nodeName, storageName)
759 fmt.Println("Pass --confirm to actually perform the restore.")
760 return nil
761 }
762
763 session, err := initCLISession(cmd)
764 if err != nil {
765 return printError(err)
766 }
767
768 if session == nil {
769 return nil
770 }
771
772 client, err := session.clientForNode(ctx, nodeName)
773 if err != nil {
774 return printError(err)
775 }
776
777 upid, err := client.RestoreGuestFromBackup(nodeName, guestType, vmid, volID, false)
778 if err != nil {
779 return printError(fmt.Errorf("failed to start restore: %w", err))
780 }
781
782 out := storageTaskOutput{
783 Node: nodeName,
784 Storage: storageName,
785 VolID: volID,
786 VMID: vmid,
787 Type: guestType,
788 UPID: upid,

Callers

nothing calls this directly

Calls 8

printErrorFunction · 0.85
inferGuestTypeFromVolIDFunction · 0.85
initCLISessionFunction · 0.85
getNoWaitFunction · 0.85
printJSONFunction · 0.85
waitForTaskFunction · 0.85
clientForNodeMethod · 0.80

Tested by

no test coverage detected