stash icon indicating copy to clipboard operation
stash copied to clipboard

postRestore hook can't be executed

Open cstaud opened this issue 5 years ago • 2 comments

In my scenario I have a statefulset with corresponding backupconfiguration. Backups run smoothly also with applied pre- and post hooks. When I apply a RestoreSession I am not able to execute the postRestore hook as there is no container where this command could be executed (beside the init-container/stash-init) where I can run a "delete some file" command.

This RestoreSession:

apiVersion: stash.appscode.com/v1beta1
kind: RestoreSession
metadata:
  name: restore
  namespace: demo
spec:
  repository:
    name: demo
  rules:
    - paths:
        - /data
  hooks:
    postRestore:
      exec:
        command:
          - /bin/sh
          - c
          - rm /data/some.file
      containerName: stash-init
  target:
    ref:
      apiVersion: apps/v1
      kind: StatefulSet
      name: demo
    volumeMounts:
      - name:  datadir
        mountPath:  /data
  runtimeSettings:
    container:
      securityContext:
        runAsUser: 999
        runAsGroup: 999

gives this error:

ok, when I try to do it this way it leads me into following error:
I0224 09:34:17.612470       1 util.go:485] Executing postRestore hooks.........                                                                                                                
W0224 09:34:18.214967       1 restore.go:239] Failed to complete restore process for RestoreSession restore. Reason: failed to execute "exec" probe. Error: could not execute: command 
terminated with exit code 2. Response: . Warning: The actual restore process may be succeeded. Hence, the restored data might be present in the target even if the overall RestoreSession phase
 is 'Failed'

cstaud avatar Feb 24 '20 10:02 cstaud

+1 I think in postRestore, the app container should be available, otherwise a lot of use cases will not be possible...

pazoozooCH avatar Jul 22 '20 22:07 pazoozooCH

Same here, without the container running the data from the backup can not be imported

Legion2 avatar Jan 06 '21 23:01 Legion2

Hey, is there any solution to this? My postRestore Hook also fails cause the container couldn't be found.

JcGKitten avatar Jan 05 '23 13:01 JcGKitten

@JcGKitten Could you please mention which Stash version you using now?

piyush1146115 avatar Jan 06 '23 05:01 piyush1146115

Hello @piyush1146115, thx for the quick reply and sorry for my short initial message.

I'm using Stash v2022.09.29 at the moment and wanted to create a postRestore Hook which runs a command on the started container named postgres. I specified the name via the containerName key word with in the RestoreSession CRD. The sessions then fails because the container with the name couldn't be found. This also happens when I don't set a specific container and it uses the first one. For BackupSessions this works like a charm but maybe I got something wrong?

Best whishes.

JcGKitten avatar Jan 07 '23 14:01 JcGKitten

Hi @JcGKitten , No worries. Thank you for your detailed reply!

Your Stash version looks recent. We will be looking into the issue very shortly and will let you know once we can figure out the root cause.

piyush1146115 avatar Jan 07 '23 18:01 piyush1146115

Hi @JcGKitten, Could you please verify if you specify your PostRestoreHook like the following works?

postRestore:
    exec:
       command: ["/bin/sh", "-c", "echo 'Hello world'"]
    containerName: stash-init

piyush1146115 avatar Jan 10 '23 06:01 piyush1146115

Yes, commands for the stash-init run in pre- and postRestore scenarios. For other containers it doesn't. BTW I'm trying to restore a Deployment, if this could make any difference.

JcGKitten avatar Jan 10 '23 09:01 JcGKitten

@JcGKitten, At the time of restoring, all the other containers except the init-container stash-init are offline. Because of this scenario, Stash could not find other containers to run postRestore hooks. However, if you need to access any volume to run a postRestore Hook, you can mount that volume to the restore init-container by using the field: restoresession.spec.target.volumeMounts

piyush1146115 avatar Jan 10 '23 10:01 piyush1146115

Ah, now I understand that, maybe I should switch to an PVC backup instead of a Deployment one. Thx a lot for your time.

JcGKitten avatar Jan 10 '23 10:01 JcGKitten

You're welcome! Let us know if you face any issues later.

piyush1146115 avatar Jan 10 '23 10:01 piyush1146115