VolSync walkthrough
1. Deploy WordPress + MariaDB
Section titled “1. Deploy WordPress + MariaDB”Each PVC gets its own restic repository, so create one Secret per PVC. Then apply the example. It
deploys WordPress, MariaDB, the seed Job, the check and the two ReplicationSources.
kubectl create namespace wordpressfor pvc in html mysql; do kubectl -n wordpress create secret generic "restic-$pvc" \ --from-literal=RESTIC_REPOSITORY="s3:https://s3.example.internal/volsync/wordpress/$pvc" \ --from-literal=RESTIC_PASSWORD=<a strong password you keep safe> \ --from-literal=AWS_ACCESS_KEY_ID=<access key> \ --from-literal=AWS_SECRET_ACCESS_KEY=<secret key>donekubectl apply -k examples/volsync -n wordpresskubectl -n wordpress wait --for=condition=Complete job/seed --timeout=15mThe app itself is in examples/wordpress/.
2. Back up
Section titled “2. Back up”examples/volsync/backup.yaml: one ReplicationSource per
PVC. A sync takes a CSI snapshot of the PVC (copyMethod: Snapshot), then copies it to the
restic repository in S3.
# VolSync backup: one ReplicationSource per PVC, each with its own restic repository in S3.# A shared repository races on init, so each PVC has its own Secret (restic-html, restic-mysql)# with RESTIC_REPOSITORY, RESTIC_PASSWORD, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.# Each sync takes a CSI snapshot, then copies it with restic. The schedule runs nightly. For one# backup now, patch spec.trigger to {manual: <id>}. The snapshot class is the kind dev name.apiVersion: volsync.backube/v1alpha1kind: ReplicationSourcemetadata: name: htmlspec: sourcePVC: html trigger: schedule: "0 2 * * *" restic: repository: restic-html copyMethod: Snapshot volumeSnapshotClassName: csi-hostpath-snapclass retain: daily: 7 moverSecurityContext: runAsUser: 33 runAsGroup: 33 fsGroup: 33---apiVersion: volsync.backube/v1alpha1kind: ReplicationSourcemetadata: name: mysqlspec: sourcePVC: mysql trigger: schedule: "0 2 * * *" restic: repository: restic-mysql copyMethod: Snapshot volumeSnapshotClassName: csi-hostpath-snapclass retain: daily: 7 moverSecurityContext: runAsUser: 999 runAsGroup: 999 fsGroup: 999The schedule runs a sync every night. To back up now, after the seed Job is done, replace the schedule with a manual trigger and wait for it:
kubectl -n wordpress patch replicationsource html mysql --type=merge \ -p '{"spec":{"trigger":{"schedule":null,"manual":"wordpress-1"}}}'kubectl -n wordpress wait --for=jsonpath='{.status.lastManualSync}'=wordpress-1 replicationsource --all --timeout=15mDo not apply a manual trigger together with the app. VolSync syncs at once, before MariaDB has created its tables, and the backup holds an empty database. Set the schedule back afterwards.
Set moverSecurityContext to the owner of the data: 33 for the WordPress docroot, 999 for
MariaDB. The default mover UID cannot read a database data dir (permission denied).
3. Write the check
Section titled “3. Write the check”The check is the same for every tool:
checks/wordpress/restorecheck.yaml. The annotation
bret.linogics.io/mover-uid gives the restore mover of each volume its UID. Without it the mover
uses the first container’s runAsUser, then 65534. How to write a check: Write a check.
4. Restore by hand, then a RestoreTest
Section titled “4. Restore by hand, then a RestoreTest”A Restore names one ReplicationSource per source:
examples/volsync/restore.yaml. Without restoreAsOf it
restores the newest restic snapshot.
# Restore: one manual restore test of the newest restic snapshot of each ReplicationSource.# backupRef names the ReplicationSource. restoreAsOf (optional) pins an older snapshot.# Restored claims: <restore>-<sourcePVC>-<hash>, here wordpress-manual-html-<hash> and wordpress-manual-mysql-<hash>.apiVersion: bret.linogics.io/v1alpha1kind: Restoremetadata: name: wordpress-manualspec: provider: volsync sources: - sourcePVC: html backupRef: name: html # The ReplicationSource of the html PVC. storageClassName: csi-hostpath-sc - sourcePVC: mysql backupRef: name: mysql storageClassName: csi-hostpath-sc restoreCheckRef: name: wordpresskubectl apply -f examples/volsync/restore.yaml -n wordpresskubectl -n wordpress wait --for=jsonpath='{.status.phase}'=Succeeded restore/wordpress-manual --timeout=15mTo see a failure, apply examples/volsync/negative/restore.yaml.
It restores only html. It ends Failed with reason SourceMissing.
A RestoreTest picks the last sync of each source and repeats the test:
examples/volsync/restoretest.yaml.
# RestoreTest: restore each PVC from its ReplicationSource and run the check.# The backup is the last sync (status.lastSyncTime). bret pins the restore to that time,# so a sync during the run does not change what is tested.apiVersion: bret.linogics.io/v1alpha1kind: RestoreTestmetadata: name: wordpressspec: provider: volsync sources: - sourcePVC: html backupSelector: name: html # The ReplicationSource. labels must match exactly one. storageClassName: csi-hostpath-sc - sourcePVC: mysql backupSelector: name: mysql storageClassName: csi-hostpath-sc restoreCheckRef: name: wordpress triggers: cron: "17 3 * * *" afterBackup: delay: 30m manual: true restoreWindow: 45m retries: count: 1 backoff: 10mkubectl apply -f examples/volsync/restoretest.yaml -n wordpresskubectl -n wordpress annotate --overwrite restoretest/wordpress bret.linogics.io/run-now="$(date +%s)"kubectl -n wordpress get restoretest wordpressAll fields: Schedule restore tests.
5. How bret picks backups
Section titled “5. How bret picks backups”VolSync has no object per backup. The backup is the last sync of a ReplicationSource.
- Object:
ReplicationSourcein theRestoreTestnamespace. backupSelector.name: thatReplicationSource.labels: theReplicationSourcewith these labels. VolSync keeps oneReplicationSourceper PVC, so labels must match exactly one. More than one blocks the test with reasonBackupSelectorAmbiguous, naming the matches.- Counts when:
status.lastSyncTimeis set. A source that never synced blocks withBackupNotFound. - Completion time:
status.lastSyncTime. - afterBackup: a run starts when every source has a newer
lastSyncTimethan the one of the last run (status.lastHandledBackups). A sync that finished before theRestoreTestwas created never starts a run, so a new test waits for the next sync. - Pinning: each
Restoresource getsrestoreAsOf= the pickedlastSyncTime. TheReplicationDestinationthen restores the newest restic snapshot at or before that time (spec.restic.restoreAsOf). A sync that lands during the run, or while a run waits in the queue or for a retry, does not change what is tested.
What bret creates:
Mover UID: the annotation bret.linogics.io/mover-uid, else runAsUser of the first check
container, else 65534.
- The
ReplicationDestinationuses a restic mover and the repository Secret of theReplicationSource. The Secret must be in theRestorenamespace. Otherwise theRestorefails withRepositoryMissing. - If
spec.sourcePVCof theReplicationSourceis not thesourcePVCof the source, theRestorefails withSourceMismatch. - The check runs when the
ReplicationDestinationreportsstatus.latestImage.kind: PersistentVolumeClaim.
