github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/docs/user_docs/backup-and-restore/backup/scheduled-backup.md (about)

     1  ---
     2  title: Scheduled backup
     3  description: How to back up databases by schedule
     4  keywords: [backup and restore, schedule, scheduled backup]
     5  sidebar_position: 5
     6  sidebar_label: Scheduled backup
     7  ---
     8  
     9  import Tabs from '@theme/Tabs';
    10  import TabItem from '@theme/TabItem';
    11  
    12  # Scheduled backup
    13  
    14  ## Backup by schedule
    15  
    16  You can customize your backup schedule by modifying relevant parameters.
    17  
    18  :::caution
    19  
    20  The backup created by kbcli or kubectl is saved permanently. If you want to delete the backup, you can delete it manually.
    21  
    22  :::
    23  
    24  <Tabs>
    25  
    26  <TabItem value="kbcli" label="kbcli" default>
    27  
    28  ```bash
    29  kbcli cluster edit-backup-policy mysql-cluster-mysql-backup-policy
    30  >
    31  spec:
    32    ...
    33    schedule:
    34      datafile:
    35        # UTC time zone, the example below stands for 2 A.M. every Monday
    36        cronExpression: "0 18 * * 0"
    37        # Enable this function
    38        enable: true
    39  ```
    40  
    41  </TabItem>
    42  
    43  <TabItem value="kubectl" label="kubectl">
    44  
    45  ```bash
    46  kubectl edit cluster -n default mysql-cluster
    47  >
    48  spec:
    49    ...
    50    backup:
    51      # Enable automatic backup
    52      enabled: true
    53      # UTC time zone, the example below stands for 2 A.M. every Monday
    54      cronExpression: 0 18 * * *
    55      # It specifies the backup method. Here is an example of backupTool. If your storage supports snapshot, you can change it to snapshot
    56      method: backupTool
    57      # Disable PITR. If enabled, automatic backup is enabled accordingly
    58      pitrEnabled: false
    59      # Retention period for a backup set
    60      retentionPeriod: 1d
    61  ```
    62  
    63  </TabItem>
    64  
    65  </Tabs>
    66  
    67  ## Backup automatically by log
    68  
    69  KubeBlocks only supports automatic log backup.
    70  
    71  ### Before you start
    72  
    73  Prepare a cluster for testing the backup and restore function. The following instructions use MySQL as an example.
    74  
    75  1. Create a cluster.
    76  
    77     ```bash
    78     kbcli cluster create mysql mysql-cluster
    79     ```
    80  
    81  2. View the backup policy.
    82  
    83     ```bash
    84     kbcli cluster list-backup-policy mysql-cluster
    85     ```
    86  
    87     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).
    88  
    89  ### Create backup
    90  
    91  <Tabs>
    92  
    93  <TabItem value="kbcli" label="kbcli" default>
    94  
    95  Currently, KubeBlocks only supports automatic log backup.
    96  
    97  1. Run the command below to enable automatic log backup.
    98  
    99     ```bash
   100     kbcli cluster edit-backup-policy mysql-cluster-mysql-backup-policy --set schedule.logfile.enable=true
   101     ```
   102  
   103  2. View the log backup to check whether the backup is successful.
   104  
   105     ```bash
   106     kbcli cluster list-backups
   107     ```
   108  
   109  </TabItem>
   110  
   111  <TabItem value="kubectl" label="kubectl">
   112  
   113  Set `pitrEnabled` in the cluster YAML configuration file as `true` to enable automatic log backup.
   114  
   115  ```bash
   116  kubectl edit cluster -n default mysql-cluster
   117  >
   118  spec:
   119    ...
   120    backup:
   121      ...
   122      # If the value is true, log backup is enabled automatically
   123      pitrEnabled: true
   124  ```
   125  
   126  </TabItem>
   127  
   128  </Tabs>