Before you back up data, you need to perform some preparatory tasks, such as configuring the backup destination and the backup key.
Configure the backup destination
When you configure the backup destination, the sys tenant, which is a cluster management tenant and does not contain user data, is not supported for backup and restore. Therefore, you do not need to configure the DATA_BACKUP_DEST parameter for the sys tenant.
Considerations
Procedure
Log in to the database as the tenant administrator of the
systenant or a user tenant.Note
In MySQL mode, the administrator user is
root. In Oracle mode, the administrator user isSYS.Configure the destination for backups.
Configure the destination for backups of a specified tenant in the sys tenant
ALTER SYSTEM SET DATA_BACKUP_DEST= 'data_backup_path' TENANT = mysql_tenant;Configure the destination for backups of the current tenant as the current tenant
The sample statement is as follows:
ALTER SYSTEM SET DATA_BACKUP_DEST= 'data_backup_path';
Notice
After upgrading from OceanBase Database V4.0.x to V4.1.0, you need to change the backup path. After upgrading from OceanBase Database V4.1.x to V4.2.0, you do not need to change the backup path.
At present, OceanBase Database supports NFS, Alibaba Cloud OSS, Tencent Cloud COS, AWS S3, and object storage services compatible with the S3 protocol, such as Huawei Cloud OBS and Google Cloud GCS. Some basic requirements may need to be met before you can use certain backup media. For more information, see the Backup media requirements section in Overview of physical backup and restore.
For more information about how to configure the destination for backups, see the following examples.
Alibaba Cloud OSSNFSTencent Cloud COSAWS S3Object storage services compatible with the S3 protocolWhen you use OSS as the destination for backups, you can also use the
delete_modeparameter to specify the cleanup mode for backup files. Thedelete_modeparameter supports thedeletemode and thetaggingmode. If you do not specify thedelete_modeparameter, thedeletemode will be used by default. For more information about thedelete_modeparameter, see View parameters for data backup.Notice
When you use an object storage service as the backup media, separate the parameters in the backup path with
&. Make sure that the parameters contain only uppercase and lowercase English letters, numbers,/-_$+=, and wildcard characters. If the parameters contain other characters, the setting may fail.Use OSS as the backup media. The sys tenant configures the destination for backups of the
mysql_tenanttenant and specifies the cleanup mode for backup files.obclient> ALTER SYSTEM SET DATA_BACKUP_DEST='oss://oceanbase-test-bucket/backup/data?host=***.aliyun-inc.com&access_id=***&access_key=***&delete_mode=delete' TENANT = mysql_tenant;Use OSS as the backup media. The user tenant configures the destination for backups of the current tenant and specifies the cleanup mode for backup files.
obclient> ALTER SYSTEM SET DATA_BACKUP_DEST='oss://oceanbase-test-bucket/backup/data?host=***.aliyun-inc.com&access_id=***&access_key=***&delete_mode=delete';
In the following example,
oss://indicates that Alibaba Cloud OSS is used as the backup media. The bucket name isoceanbase-test-bucket, and the path within the bucket is/backup/data. The parameters in the path are separated with?.hostis used to set the host address of the bucket, which is the endpoint address (excluding the bucket name).access_idandaccess_keyare used to set the access key ofOSS. The cleanup mode is set todelete.After you set the
deletemode or thetaggingmode, for more information about how to automatically clear expired backup data, see Automatic cleanup of backup data.Notice
When you use NFS as the backup media, note that:
- The value of the
data_backup_destparameter must not contain a question mark (?). - The value of the
data_backup_destparameter must be an absolute path. The OBServer node must have write permissions fordata_backup_dest. - All OBServer nodes must mount the same NFS server. To ensure smooth backup, it is recommended to use the parameters specified in this topic to mount NFS. For more information, see Deploy an NFS client.
Use NFS as the backup media. The sys tenant configures the destination for backups of the
mysql_tenanttenant.obclient> ALTER SYSTEM SET DATA_BACKUP_DEST= 'file:///data/nfs/backup/data' TENANT = mysql_tenant;Use NFS as the backup media. The user tenant configures the destination for backups of the current tenant.
obclient> ALTER SYSTEM SET DATA_BACKUP_DEST='file:///data/nfs/backup/data';
In the following example,
file://indicates that NFS is used as the backup media. The backup path isfile:///data/nfs/backup/data.COS supports the
delete_modeparameter to specify the cleanup mode for backup files. The configuration of thedelete_modeparameter is the same as that for Alibaba Cloud OSS.Notice
When you use an object storage service as the backup media, separate the parameters in the backup path with
&. Make sure that the parameters contain only uppercase and lowercase English letters, numbers,/-_$+=, and wildcard characters. If the parameters contain other characters, the setting may fail.Use COS as the backup media. The sys tenant configures the destination for backups of the
mysql_tenanttenant.obclient> ALTER SYSTEM SET DATA_BACKUP_DEST='cos://oceanbase-test-appid/backup/data?host=cos.ap-****.myqcloud.com&access_id=***&access_key=***&appid=***' TENANT = mysql_tenant;Use COS as the backup media. The user tenant configures the destination for backups of the current tenant.
obclient> ALTER SYSTEM SET DATA_BACKUP_DEST='cos://oceanbase-test-appid/backup/data?host=cos.ap-****.myqcloud.com&access_id=***&access_key=***&appid=***';
In the following example,
cos://indicates that Tencent Cloud COS is used as the backup media. The bucket name isoceanbase-test-appid, and the path within the bucket is/backup/data. The parameters in the path are separated with?.hostis used to set the host address of COS, which is the endpoint address (excluding the bucket name).access_idandaccess_keyare used to set the access key ofCOS. The optional parameterappidis used to set the APPID of the Tencent cloud account. The cleanup mode is set todelete.AWS S3 supports the
delete_modeparameter to specify the cleanup mode for backup files. The configuration of thedelete_modeparameter is the same as that for Alibaba Cloud OSS and Tencent Cloud COS.Notice
When you use an object storage service as the backup media, separate the parameters in the backup path with
&. Make sure that the parameters contain only uppercase and lowercase English letters, numbers,/-_$+=, and wildcard characters. If the parameters contain other characters, the setting may fail.Use S3 as the backup media. The sys tenant configures the destination for backups of the
mysql_tenanttenant and specifies thedeletemode as the cleanup mode.obclient> ALTER SYSTEM SET DATA_BACKUP_DEST='s3://oceanbase-test-bucket/backup/data?host=s3.<region>.amazonaws.com&access_id=***&access_key=***&s3_region=***&delete_mode=delete' TENANT = mysql_tenant;Use S3 as the backup media. The user tenant configures the destination for backups of the current tenant and specifies the
deletemode as the cleanup mode.obclient> ALTER SYSTEM SET DATA_BACKUP_DEST='s3://oceanbase-test-bucket/backup/data?host=s3.<region>.amazonaws.com&access_id=***&access_key=***&s3_region=***&delete_mode=delete';
In the following example,
s3://indicates that AWS S3 is used as the backup media. The bucket name isoceanbase-test-bucket, and the path within the bucket is/backup/data. The parameters in the path are separated with?.hostis used to set the domain name of the Amazon S3 service.access_idandaccess_keyare used to set the access key of AWS. The optional parameters3_regionis used to specify the region where the S3 bucket is located. The cleanup mode is set todelete.Most object storage services are compatible with the S3 protocol. You can use these object storage services as the backup media for OceanBase Database after they meet the requirements for OceanBase Database. You can access compatible object storage services in the same way as you access S3, for example, OBS and GCS.
Notice
When you use an object storage service as the backup media, separate the parameters in the backup path with
&. Make sure that the parameters contain only uppercase and lowercase English letters, numbers,/-_$+=, and wildcard characters. If the parameters contain other characters, the setting may fail.The following example shows how to configure an object storage service compatible with the S3 protocol as the destination for backups:
Use OBS as the backup media. The sys tenant configures the destination for backups of the
mysql_tenanttenant.obclient> ALTER SYSTEM SET DATA_BACKUP_DEST='s3://oceanbase-test-bucket/backup/data?host=obs.****.myhuaweicloud.com&access_id=****&access_key=****' TENANT = mysql_tenant;Use OBS as the backup media. The user tenant configures the destination for backups of the current tenant and specifies the cleanup mode.
obclient> ALTER SYSTEM SET DATA_BACKUP_DEST='s3://oceanbase-test-bucket/backup/data?host=obs.****.myhuaweicloud.com&access_id=****&access_key=****';
In the preceding example,
s3://indicates that an object storage service compatible with the S3 protocol is used as the backup media. The bucket name isoceanbase-test-bucket, and the path within the bucket is/backup/data. The parameters in the path are separated with?.hostis used to set the domain name of the OBS service.access_idandaccess_keyare used to set the access key of the OBS service.The following example shows how to configure GCS as the destination for backups:
Use GCS as the backup media. The sys tenant configures the destination for backups of the
mysql_tenanttenant.obclient> ALTER SYSTEM SET DATA_BACKUP_DEST='s3://oceanbase-test-bucket/backup/data?host=https://storage.googleapis.com&access_id=****&access_key=****' TENANT = mysql_tenant;Use GCS as the backup media. The user tenant configures the destination for backups of the current tenant.
obclient> ALTER SYSTEM SET DATA_BACKUP_DEST='s3://oceanbase-test-bucket/backup/data?host=https://storage.googleapis.com&access_id=****&access_key=****';
In the preceding example,
s3://indicates that an object storage service compatible with the S3 protocol is used as the backup media. The bucket name isoceanbase-test-bucket, and the path within the bucket is/backup/data. The parameters in the path are separated with?.hostis used to set the domain name of the GCS service.access_idandaccess_keyare used to set the access key of the GCS service.
Considerations and notes after configuration
After the data_backup_dest parameter is successfully configured, the default system creates a format file in the specified directory as a verification file to check the validity of the backup destination and the integrity of the data in the destination. Therefore, when you configure the data_backup_dest parameter, note the following considerations:
If the
formatfile does not exist, the specified destination directory must be empty. Otherwise, an error-9080will occur, indicating that theformatfile does not exist.If the
formatfile already exists, its content must pass the verification. Otherwise, an error-9081will occur, indicating that theformatfile is mismatched. The verification of theformatfile checks whether the cluster, tenant, and backup destination type are the same as those of the current operation.If the
formatfile does not exist or its content verification fails during a backup task, the task will fail.
Back up the keys
Before you back up data, check the encryption status of the source tenant. If transparent encryption is configured for the source tenant, you must also back up the keys of the source tenant.
Notice
If the encryption information of the source tenant triggers a key rotation before you restore the data, you must back up the keys of the source tenant again.
Log in to the database as the tenant administrator of the
systenant or a user tenant.Back up the keys.
Back up the keys of a specified tenant in the sys tenant
ALTER SYSTEM BACKUP KEY TENANT = tenant_name TO 'backup_key_path' ENCRYPTED BY 'password';Back up the keys of the current tenant in a user tenant
Execute the following statement:
ALTER SYSTEM BACKUP KEY TO 'backup_key_path' ENCRYPTED BY 'password';
In the statements:
backup_key_path: the path where the keys are to be backed up. You need to specify this parameter. It cannot be the same as the path for backing up data or archiving logs. You can customize this path.password: the password for encrypting the keys at the specified backup path.
Here is an example of backing up the keys of the
mysql_tenanttenant to thefile:///data_backup_dest/keypath in the sys tenant:obclient [(none)]> ALTER SYSTEM BACKUP KEY TENANT = mysql_tenant TO 'file:///data_backup_dest/key' ENCRYPTED BY '******';After the configuration is successful, you can query the view for the path where the keys are backed up.
Query the
CDB_OB_BACKUP_STORAGE_INFOview in the sys tenant for the path where the keys are backed upSELECT * FROM oceanbase.CDB_OB_BACKUP_STORAGE_INFO;Query the
DBA_OB_BACKUP_STORAGE_INFOview in a user tenant for the path where the keys are backed upMySQL modeOracle modeExecute the following statement:
SELECT * FROM oceanbase.DBA_OB_BACKUP_STORAGE_INFO;Execute the following statement:
SELECT * FROM SYS.DBA_OB_BACKUP_STORAGE_INFO;For more information about the fields in the
CDB_OB_BACKUP_STORAGE_INFOandDBA_OB_BACKUP_STORAGE_INFOviews, see CDB_OB_BACKUP_STORAGE_INFO and DBA_OB_BACKUP_STORAGE_INFO.