Add Backup Rules
Backup rules are database-dependent scripts executed on containers before or after the backup operation to ensure application-consistent backups. Rules executed before and after the backup operation are called pre-exec and post-exec rules respectively. These rules are predominantly used to either freeze or unfreeze input/output operations of applications to facilitate Portworx Backup to take consistent backups.
In the backend, Portworx Backup initiates a Pod (cmdexecutor) to execute the required rules on the container based on labels applied to the Deployments. If you have applied the same label to a set of Deployments, the cmdexecutor Pod selects all of them and applies the defined rule or set of rules.
Some applications may only require freeze or pre-exec rules. If you want to add multiple instructions to a rule, you can add sub-rules. For example, while backing up an Elasticsearch application, you can add a sub-rule for a health check along with the freeze operation.
To create a pre-exec rule for backup:
-
Log in and access the Portworx Backup home page.
-
In the left navigation pane, click Rules.
-
In the Backup Rules page, click Create Rules:
-
In the Create Rules page, build your rule by populating the following fields:
-
Rule Name: Enter a descriptive name for your rule.
-
Pod selector: Enter any label selectors based on your Pod’s labels. For example,
app=postgresuses the app label to select Pods runningpostgres. Use any of the equality-based selector operators. Make sure there is no space before or after the=sign.For more information on labeling guidelines, refer to labeling guidelines.
-
Container (Optional): Enter the name of the container to which Portworx Backup applies the rule.
-
Action: Enter any commands you want to execute when the rule is triggered.
-
Background: Enable this if you want the rule to run in the background. The rule runs as a background process and can be used to back up crash-consistent applications (for example, MySQL).
-
Run in single pod: Run this rule in a single Pod. The Kubernetes scheduler chooses the Pod and can be used to take a backup of lead-based applications (for example, MongoDB).
-
+ icon: Click this icon if you need to add more than one action to the same application.
-
-
(Optional): Select the + Add icon to add more sub-rules if you have more than one container for the chosen application (Pod selector) or if you need to apply rules for more than one application at the same time.
-
Click Add to create the pre-exec rule:
After you create this pre-exec rule, the rule is listed in the Backup Rules page. You can later associate this rule with a backup. The pre-exec rule is applied before the backup is created.
Similarly, you can create post-exec rules for the required applications. The post-exec rule is applied after the backup is created.
Related topic