Skip to main content
Version: 3.3

Configure pre-exec and post-exec rules for Stork migrations

This page explains how to use pre-exec and post-exec rules with Stork migrations.

  • A pre-exec rule runs before volume migrations and helps create consistent snapshots by pausing writes, flushing logs, or freezing a virtual machine (VM).
  • A post-exec rule runs after volume snapshots are created and helps applications return to normal operations, for example, resuming writes or unfreezing a VM.

The examples show how to configure rules for a MySQL app and for KubeVirt VMs.

Pre-exec rule

Use a pre-exec rule to pause writes before migration. This helps ensure the application is in a consistent state when migration begins.

apiVersion: stork.libopenstorage.org/v1alpha1
kind: Rule
metadata:
name: mysql-pre-migration
namespace: portworx
rules:
- podSelector:
app: mysql
actions:
- type: command
background: true
value: mysql --user=root --password=$MYSQL_ROOT_PASSWORD -Bse 'FLUSH TABLES WITH READ LOCK; SYSTEM ${WAIT_CMD};'

Post-exec rule

Use a post-exec rule to resume normal application operation after migration. This helps ensure that writes and I/O continue safely on the source cluster.

apiVersion: stork.libopenstorage.org/v1alpha1
kind: Rule
metadata:
name: mysql-post-migration
namespace: portworx
rules:
- podSelector:
app: mysql
actions:
- type: command
value: mysql --user=root --password=$MYSQL_ROOT_PASSWORD -Bse 'FLUSH LOGS; UNLOCK TABLES;'

Migration schedule

After creating rules, refer to them in a migration schedule.

note

You can also use pre-exec and post-exec rules when running a direct migration using storkctl create migration, not only with migration schedules.

storkctl create migrationschedule \
-c <cluster-pair> \
--namespaces <mysql1> \
--pre-exec-rule <mysql-pre-migration> \
--post-exec-rule <mysql-post-migration> \
<mysql-schedule>