github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/docs/user_docs/backup-and-restore/backup/on-demand-backup.md (about) 1 --- 2 title: On-demand backup 3 description: How to back up databases on-demand by snapshot and backup tool 4 keywords: [backup, on-demand backup, snapshot backup, backup tool] 5 sidebar_position: 3 6 sidebar_label: On-demand backup 7 --- 8 9 import Tabs from '@theme/Tabs'; 10 import TabItem from '@theme/TabItem'; 11 12 # On-demand backup 13 14 ## Before you start 15 16 Prepare a cluster for testing the backup and restore function. The following instructions use MySQL as an example. 17 18 1. Create a cluster. 19 20 ```bash 21 kbcli cluster create mysql mysql-cluster 22 ``` 23 24 2. View the backup policy. 25 26 ```bash 27 kbcli cluster list-backup-policy mysql-cluster 28 ``` 29 30 By default, all the backups are stored in the default global repository but you can specify a new repository by [editing the BackupPolicy resource](./backup-repo.md#optional-change-the-backup-repository-for-a-cluster). 31 32 ## Create backup 33 34 KubeBlocks supports two backup options: backup tool and snapshot backup. 35 36 ### Backup tool 37 38 Both kbcli and kubectl are supported. 39 40 <Tabs> 41 42 <TabItem value="kbcli" label="kbcli" default> 43 44 1. View the cluster status and make sure the cluster is `Running`. 45 46 ```bash 47 kbcli cluster list mysql-cluster 48 ``` 49 50 2. Create a backup. 51 52 ```bash 53 kbcli cluster backup mysql-cluster --type=datafile 54 ``` 55 56 3. View the backup set. 57 58 ```bash 59 kbcli cluster list-backups mysql-cluster 60 ``` 61 62 </TabItem> 63 64 <TabItem value="kubectl" label="kubectl"> 65 66 Run the command below to create a backup named `mybackup`. 67 68 ```bash 69 kubectl apply -f - <<-'EOF' 70 apiVersion: dataprotection.kubeblocks.io/v1alpha1 71 kind: Backup 72 metadata: 73 name: mybackup 74 namespace: default 75 spec: 76 backupPolicyName: mycluster-mysql-backup-policy 77 backupType: datafile 78 EOF 79 ``` 80 81 </TabItem> 82 83 </Tabs> 84 85 ### Snapshot backup 86 87 Both kbcli and kubectl are supported. 88 89 <Tabs> 90 91 <TabItem value="kbcli" label="kbcli" default> 92 93 1. View the cluster status and make sure the cluster is `Running`. 94 95 ```bash 96 kbcli cluster list mysql-cluster 97 ``` 98 99 2. Create a snapshot backup. 100 101 ```bash 102 kbcli cluster backup mysql-cluster --type=snapshot 103 ``` 104 105 3. View the backup set to check whether the backup is successful. 106 107 ```bash 108 kbcli cluster list-backups mysql-cluster 109 ``` 110 111 </TabItem> 112 113 <TabItem value="kubectl" label="kubectl"> 114 115 Run the command below to create a snapshot backup named `mysnapshot`. 116 117 ```bash 118 kubectl apply -f - <<-'EOF' 119 apiVersion: dataprotection.kubeblocks.io/v1alpha1 120 kind: Backup 121 metadata: 122 name: mysnapshot 123 namespace: default 124 spec: 125 backupPolicyName: mycluster-mysql-backup-policy 126 backupType: snapshot 127 EOF 128 ``` 129 130 </TabItem> 131 132 </Tabs>