<p>How do I configure Longhorn backup so it executes some bash scripts in the pod before and after snapshot/backup is taken?</p>
<p>Something similar to Velero's backup hooks.</p>
<pre><code>  annotations:
    backup.velero.io/backup-volumes: data
    pre.hook.backup.velero.io/command: &quot;['/usr/bin/mysql', '-e', '\&quot;flush tables with read lock;\&quot;']&quot;
    pre.hook.backup.velero.io/container: mysql
    post.hook.backup.velero.io/command: &quot;['/usr/bin/mysql', '-e', '\&quot;unlock tables;\&quot;']&quot;
    post.hook.backup.velero.io/container: mysql
</code></pre>

<p>Apparently not possible at the moment, according to the <a href="https://github.com/longhorn/longhorn/issues/2164#issuecomment-756792572" rel="nofollow noreferrer">longhorn github issue</a>.</p>
<p>You can orchestrate similar behaviour by using <a href="https://kubernetes.io/docs/concepts/storage/volume-snapshots/" rel="nofollow noreferrer">volume snapshot</a></p>
<pre><code>kubectl exec mypod-id -- app_freeze
kubectl apply -f volumesnapshot.yaml
kubectl exec mypod-id -- app_thaw
</code></pre>
<p>Where <code>volumesnapshot.yaml</code> is:</p>
<pre><code>apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
  name: my-longhorn-snapshot
spec:
  volumeSnapshotClassName: longhorn
  source:
    persistentVolumeClaimName: my-longhorn-pvc
</code></pre>
<p>See example for IRIS database: <a href="https://community.intersystems.com/post/amazon-eks-and-iris-high-availability-and-backup" rel="nofollow noreferrer">https://community.intersystems.com/post/amazon-eks-and-iris-high-availability-and-backup</a></p>
