Scheduled snapshots


Stork version

Stork version 2.2 or above is required.

Configuring cloud secrets

To create cloud snapshots, one needs to setup secrets with Portworx which will get used to connect and authenticate with the configured cloud provider.

Follow instructions on the pxctl credentials page to setup secrets.


Perform the following steps to download storkctl from the Stork pod:

  • Linux:

    STORK_POD=$(kubectl get pods -n kube-system -l name=stork -o jsonpath='{.items[0]}') &&
    kubectl cp -n kube-system $STORK_POD:/storkctl/linux/storkctl ./storkctl
    sudo mv storkctl /usr/local/bin &&
    sudo chmod +x /usr/local/bin/storkctl
  • OS X:

    STORK_POD=$(kubectl get pods -n kube-system -l name=stork -o jsonpath='{.items[0]}') &&
    kubectl cp -n kube-system $STORK_POD:/storkctl/darwin/storkctl ./storkctl
    sudo mv storkctl /usr/local/bin &&
    sudo chmod +x /usr/local/bin/storkctl
  • Windows:

    1. Copy storkctl.exe from the stork pod:

      STORK_POD=$(kubectl get pods -n kube-system -l name=stork -o jsonpath='{.items[0]}') &&
      kubectl cp -n kube-system $STORK_POD:/storkctl/windows/storkctl.exe ./storkctl.exe
    2. Move storkctl.exe to a directory in your PATH

Creating a schedule policy

Schedule policies can be used to specify when a specific action has to be triggered. There are 4 sections in a schedule policy spec:

  • Interval: the interval in minutes after which the action should be triggered
  • Daily: the time at which the action should be triggered every day
  • Weekly: the day of the week and the time in that day when the action should be triggered
  • Monthly: the date of the month and the time on that date when the action should be triggered.
Note that scheduled snapshots do not occur if the volume you are trying to snapshot is not attached to a container.

Let’s look at an example of how we could create a daily and weekly policy.

Create a daily policy with the following policy-daily.yaml:

kind: SchedulePolicy
  name: daily
    time: "10:14PM"
    retain: 3
kubectl apply -f policy-daily.yaml created

Similarly, create a weekly policy with the following policy-weekly.yaml:

kind: SchedulePolicy
  name: weekly
    day: "Thursday"
    time: "10:13PM"
    retain: 2
kubectl apply -f policy-weekly.yaml

If you want to check the status of our schedule policy, type:

storkctl get schedulepolicy
daily     N/A                10:14PM   N/A                N/A
weekly    N/A                N/A       Thursday@10:13PM   N/A

Associate a schedule policy with a StorageClass or a Volume

Once you’ve defined a schedule policy, you can create and associate StorageClass and Volume specs with it. Perform one of the following steps, depending on whether you want to schedule snapshots for multiple PVCs or a single volume:

Create a VolumeSnapshotSchedule

You can create VolumeSnapshotSchedules to backup specific volumes according to a schedule you define.

Create a VolumeSnapshotSchedule, specifying:

  • metadata:
    • name: with the name of this VolumeSnapshotSchedule policy
    • namespace: the namespace in which this policy will exist
    • annotations:
      • portworx/snapshot-type: with the cloud or local value, depending on what environment you want store your snapshots in
      • portworx/cloud-cred-id: with your cloud environment credentials
      • stork/snapshot-restore-namespaces: with other namespaces snapshots taken with this policy can restore to
  • spec:
    • schedulePolicyName: with the name of the schedule policy you defined in the steps above
    • suspend: with a boolean value specifying if the schedule should be in a suspended state
    • preExecRule: with the name of a rule to run before taking the snapshot
    • postExecRule: with the name of a rule to run after taking the snapshot
    • reclaimPolicy: with retain or delete, indicating what Portworx should do with the snapshots that were created using the schedule. Specifying the delete value deletes the snapshots created by this schedule when the schedule is deleted.
    • template:
      • spec:
      • persistentVolumeClaimName: with the PVC you want this policy to apply to
kind: VolumeSnapshotSchedule
  name: mysql-snapshot-schedule
  namespace: mysql
    portworx/snapshot-type: cloud
    portworx/cloud-cred-id: <cred_id>
    stork/snapshot-restore-namespaces: otherNamespace
  schedulePolicyName: testpolicy
  suspend: false
  reclaimPolicy: Delete
  preExecRule: testRule
  postExecRule: otherTestRule
      persistentVolumeClaimName: mysql-data

Create a storage class

Now that we’ve defined a schedule policy let’s create a new StorageClass spec. By adding the new annotations, it’ll automatically create a schedule for the newly created PVCs.

Create a new file called sc-with-snap-schedule.yaml and paste into it the content from below:

kind: StorageClass
    name: px-sc-with-snap-schedules
   repl: "2" |
     schedulePolicyName: daily
       portworx/snapshot-type: local |
     schedulePolicyName: weekly
       portworx/snapshot-type: cloud
       portworx/cloud-cred-id: <credential-uuid>

The above StorageClass references 2 schedules. The default-schedule backs up volumes to the local Portworx cluster on a daily basis. The weekly-schedule backs up volumes to cloud storage on a weekly basis.

Specifying the cloud credential to use

Specifying the portworx/cloud-cred-id is required only if you have more than one cloud credentials configured. If you have a single one, by default, that credential is used.

Let’s list all the available cloud credentails we have.

PX_POD=$(kubectl get pods -l name=portworx -n kube-system -o jsonpath='{.items[0]}')
kubectl exec $PX_POD -n kube-system -- /opt/pwx/bin/pxctl credentials list

The above command will output the credentials required to authenticate/access the objectstore. Pick the one you want to use for this snapshot schedule and specify it in the portworx/cloud-cred-id annotation in the StorageClass.

Next, let’s apply our newly created storage class:

kubectl apply -f sc-with-snap-schedule.yaml created

Create a PVC

After we’ve created the new StorageClass, we can refer to it by name in our PVCs like this:

kind: PersistentVolumeClaim
apiVersion: v1
  name: pvc-snap-schedules-demo
  annotations: px-sc-with-snap-schedules
    - ReadWriteOnce
      storage: 2Gi

Paste the listing from above into a file named pvc-snap-schedules-demo.yaml and run:

kubectl create -f pvc-snap-schedules-demo.yaml
persistentvolumeclaim/pvc-snap-schedules-demo created

Let’s see our PVC:

kubectl get pvc
NAME                      STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS                AGE
pvc-snap-schedules-demo   Bound    pvc-3491fc8a-6222-11e9-89a9-080027ee1df7   2Gi        RWO            px-sc-with-snap-schedules   14s

The above output shows that a volume named pvc-3491fc8a-6222-11e9-89a9-080027ee1df7 was automatically created and is now bounded to our PVC.

We’re all set!

Checking snapshots

Verifying snapshot schedules

First let’s verify that the snapshot schedules are created correctly.

storkctl get volumesnapshotschedules
NAME                                       PVC                       POLICYNAME   PRE-EXEC-RULE   POST-EXEC-RULE   RECLAIM-POLICY   SUSPEND   LAST-SUCCESS-TIME
pvc-snap-schedules-demo-default-schedule   pvc-snap-schedules-demo   daily                                         Retain           false
pvc-snap-schedules-demo-weekly-schedule    pvc-snap-schedules-demo   weekly                                        Retain           false

Here we can see 2 snapshot schedules, one daily and one weekly.

Verifying snapshots

Now that we’ve put everything in place, we would want to verify that our cloudsnaps are created.

Using storkctl

Also, you can use storkctl to make sure that the snapshots are created by running:

storkctl get volumesnapshots
NAME                                                                  PVC                       STATUS    CREATED               COMPLETED             TYPE
pvc-snap-schedules-demo-default-schedule-interval-2019-03-27-015546   pvc-snap-schedules-demo   Ready     26 Mar 19 21:55 EDT   26 Mar 19 21:55 EDT   local
pvc-snap-schedules-demo-weekly-schedule-interval-2019-03-27-015546    pvc-snap-schedules-demo   Ready     26 Mar 19 21:55 EDT   26 Mar 19 21:55 EDT   cloud

Last edited: Friday, Apr 10, 2020