stash
stash copied to clipboard
postRestore hook can't be executed
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'
+1 I think in postRestore, the app container should be available, otherwise a lot of use cases will not be possible...
Same here, without the container running the data from the backup can not be imported
Hey, is there any solution to this? My postRestore Hook also fails cause the container couldn't be found.
@JcGKitten Could you please mention which Stash version you using now?
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.
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.
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
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, 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
Ah, now I understand that, maybe I should switch to an PVC backup instead of a Deployment one. Thx a lot for your time.
You're welcome! Let us know if you face any issues later.