CrunchyData / postgres-operator-client

Apache License 2.0
15 stars 13 forks source link

disable restore postgres-operator-client #59

Closed Eric-zch closed 1 year ago

Eric-zch commented 1 year ago

Thanks for developing such a user friendly tool postgres-operator-client, I love it. So I followed this page https://access.crunchydata.com/documentation/postgres-operator-client/0.2.0/reference/ to test some functions I often use. I can do backup and restore with it successfuly.

after I restored successfully with oc pgo restore command, I want to disable the restore, so I issued command:

[zhaoch@~]$oc pgo restore disable pnst
Error: PostgresCluster.postgres-operator.crunchydata.com "pnst" is invalid: spec.backups.pgbackrest.restore.repoName: Required value
[zhaoch@~]$
[zhaoch@~]$oc pgo version
Client Version: v0.2.0
Operator Version: v5.3.0
[zhaoch@~]$
[zhaoch@~]$oc pgo restore disable -h
Update a PostgresCluster spec to disable restores.

This is recommended after your restore is complete. Running "pgo restore" will enable restores again.

RBAC Requirements:
    Resources                                           Verbs
    ---------                                           -----
    postgresclusters.postgres-operator.crunchydata.com  [get patch]

Usage:
  pgo restore disable CLUSTER_NAME [flags]

Flags:
  -h, --help   help for disable

Global Flags:
      --as string                      Username to impersonate for the operation. User could be a regular user or a service account in a namespace.
      --as-group stringArray           Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
      --as-uid string                  UID to impersonate for the operation.
      --cache-dir string               Default cache directory (default "/home/zhaoch/.kube/cache")
      --certificate-authority string   Path to a cert file for the certificate authority
      --client-certificate string      Path to a client certificate file for TLS
      --client-key string              Path to a client key file for TLS
      --cluster string                 The name of the kubeconfig cluster to use
      --context string                 The name of the kubeconfig context to use
      --insecure-skip-tls-verify       If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
      --kubeconfig string              Path to the kubeconfig file to use for CLI requests.
  -n, --namespace string               If present, the namespace scope for this CLI request
      --request-timeout string         The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
  -s, --server string                  The address and port of the Kubernetes API server
      --tls-server-name string         Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used
      --token string                   Bearer token for authentication to the API server
      --user string                    The name of the kubeconfig user to use
[zhaoch@~]$

My postgrescluster pnst has below configuration after the restore.

spec:
  backups:
    pgbackrest:
      (ignore)
      restore:
        enabled: true
        options:
        - --type=immediate --set='20230323-073800F'
        repoName: repo1

Could you please let me know why I got this error message?

[zhaoch@~]$oc pgo restore disable pnst
Error: PostgresCluster.postgres-operator.crunchydata.com "pnst" is invalid: spec.backups.pgbackrest.restore.repoName: Required value
boris-lenzinger commented 1 year ago

Hi Eric-zch,

Hi have tried to reproduce your problem. My current version is:

$> kubectl-pgo version
Client Version: v0.3.0
Operator Version: v5.3.0

To be in the same conditions, I created a crunchy cluster, made 3 backups:

stanza: db
    status: ok
    cipher: none

    db (current)
        wal archive min/max (14): 000000010000000000000001/000000010000000000000006

        full backup: 20230423-185330F
            timestamp start/stop: 2023-04-23 18:53:30 / 2023-04-23 18:53:39
            wal start/stop: 000000010000000000000002 / 000000010000000000000002
            database size: 33.5MB, database backup size: 33.5MB
            repo1: backup set size: 4.2MB, backup size: 4.2MB

        full backup: 20230423-185348F
            timestamp start/stop: 2023-04-23 18:53:48 / 2023-04-23 18:53:57
            wal start/stop: 000000010000000000000004 / 000000010000000000000004
            database size: 33.6MB, database backup size: 33.6MB
            repo1: backup set size: 4.2MB, backup size: 4.2MB

        full backup: 20230423-185450F
            timestamp start/stop: 2023-04-23 18:54:50 / 2023-04-23 18:54:55
            wal start/stop: 000000010000000000000006 / 000000010000000000000006
            database size: 33.7MB, database backup size: 33.7MB
            repo1: backup set size: 4.2MB, backup size: 4.2MB

Then restore the cluster with the kubectl pgo :+1:

$> kubectl-pgo restore source-cluster -n test-clone --repoName repo1  --options '--type=time --target="2023-04-23 18:53:57"'

when the restoration completed, I executed the command:

$> kubectl-pgo restore disable source-cluster -n test-clone
postgresclusters/source-cluster patched

May be you should upgrade to the latest version.

Eric-zch commented 1 year ago

Hi @boris-lenzinger May I know where I can get client version v0.3.0? From https://github.com/CrunchyData/postgres-operator-client/releases, the latest version is v0.2.0

boris-lenzinger commented 1 year ago

Hi @Eric-zch ,

I have rebuilt the repository. I didn't notice that the published version was 0.2 ! The version is in the file pgo.go in package cmd. You can check that it is now 0.3. Rebuilt is quite easy. Download Go, add the bin folder to the path and execute make build. This will produce the binary in the bin folder.

Eric-zch commented 1 year ago

Hi @boris-lenzinger Thank you.

benjaminjb commented 1 year ago

@Eric-zch Thanks for the kind words about the postgres-operator-client and @boris-lenzinger thanks for working through the issue!

This seems complete, so I'll close this issue, but feel free to reopen if there's something I missed.