func PhysicalBackup()

in oracle/pkg/agents/backup/backup.go [99:190]


func PhysicalBackup(ctx context.Context, params *Params) (*lropb.Operation, error) {
	klog.InfoS("oracle/PhysicalBackup", "params", params)

	var channels string
	for i := 1; i <= int(params.DOP); i++ {
		channels += fmt.Sprintf(allocateChannel, i)
	}
	klog.InfoS("oracle/PhysicalBackup", "channels", channels)

	granularity := "database"
	if params.Granularity != "" {
		granularity = params.Granularity
	}

	backupDir := consts.DefaultRMANDir
	if params.LocalPath != "" {
		backupDir = params.LocalPath
	}
	// for RMAN backup to GCS bucket, first backup to a staging location. Remove staging dir when upload finishes.
	if params.GCSPath != "" {
		backupDir = consts.RMANStagingDir
	}
	klog.InfoS("oracle/PhysicalBackup", "backupDir", backupDir)

	dirInfo := []*dbdpb.CreateDirsRequest_DirInfo{
		{
			Path: backupDir,
			Perm: 0760,
		},
	}

	// Check/create the destination dir if it's different from the default.
	if _, err := params.Client.CreateDirs(ctx, &dbdpb.CreateDirsRequest{
		Dirs: dirInfo,
	}); err != nil {
		return nil, fmt.Errorf("failed to create a backup dir %q: %v", backupDir, err)
	}

	if params.Compressed && !params.Backupset {
		return nil, fmt.Errorf("oracle/PhysicalBackup: failed a pre-flight check: Image Copy type of backup is not compatible with a Compress setting")
	}

	var compressed string
	if params.Compressed {
		compressed = "compressed"
	}

	var backupset string
	if params.Backupset {
		backupset = "backupset"
	} else {
		backupset = "copy"
	}
	klog.InfoS("oracle/PhysicalBackup", "backupset", backupset)

	checklogical := "check logical"
	if !params.CheckLogical {
		checklogical = ""
	}
	klog.InfoS("oracle/PhysicalBackup", "checkLogical", checklogical)

	filesperset := ""
	if params.Filesperset != 0 {
		filesperset = fmt.Sprintf("filesperset %d", params.Filesperset)
	}
	klog.InfoS("oracle/PhysicalBackup", "filesperset", filesperset)

	sectionSize := sectionSize(params.SectionSize)
	klog.InfoS("oracle/PhysicalBackup", "sectionSize", sectionSize)

	// Change the location of RMAN control file snapshot from
	// the container image filesystem to the data disk (<backupDir>/snapcf_<CDB>.f)
	// The default location is '/u01/app/oracle/product/<VERSION>/db/dbs/snapcf_<CDB>.f'
	// and it causes flaky behaviour (ORA-00246) in Oracle 19.3
	initStatement := fmt.Sprintf("CONFIGURE SNAPSHOT CONTROLFILE NAME TO '%s/snapcf_%s.f';", backupDir, params.CDBName)

	tag := params.BackupTag
	backupStmt := fmt.Sprintf(backupStmtTemplate, initStatement, channels, compressed, backupset, checklogical, filesperset, sectionSize, params.Level, backupDir, tag, granularity, backupDir, tag)
	klog.InfoS("oracle/PhysicalBackup", "finalBackupRequest", backupStmt)

	backupReq := &dbdpb.RunRMANAsyncRequest{
		SyncRequest: &dbdpb.RunRMANRequest{Scripts: []string{backupStmt}, GcsPath: params.GCSPath, LocalPath: params.LocalPath, GcsOp: dbdpb.RunRMANRequest_UPLOAD},
		LroInput:    &dbdpb.LROInput{OperationId: params.OperationID},
	}
	klog.InfoS("oracle/PhysicalBackup", "backupReq", backupReq)

	operation, err := params.Client.RunRMANAsync(ctx, backupReq)
	if err != nil {
		return nil, fmt.Errorf("oracle/PhysicalBackup: failed to create database backup request: %v", err)
	}
	return operation, nil
}