github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/parsers/tree/backup.go (about)

     1  // Copyright 2023 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //	http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package tree
    16  
    17  import "github.com/matrixorigin/matrixone/pkg/common/reuse"
    18  
    19  func init() {
    20  	reuse.CreatePool[BackupStart](
    21  		func() *BackupStart { return &BackupStart{} },
    22  		func(b *BackupStart) { b.reset() },
    23  		reuse.DefaultOptions[BackupStart](), //.
    24  	) //WithEnableChecker()
    25  }
    26  
    27  type BackupStart struct {
    28  	statementImpl
    29  	Timestamp   string
    30  	IsS3        bool
    31  	Dir         string
    32  	Parallelism string
    33  	// s3 option
    34  	Option []string
    35  
    36  	// incremental backup
    37  	BackupType string
    38  	BackupTs   string
    39  }
    40  
    41  func (node *BackupStart) Format(ctx *FmtCtx) {
    42  	ctx.WriteString("backup ")
    43  	ctx.WriteString(node.Timestamp)
    44  	ctx.WriteString(" ")
    45  	if node.IsS3 {
    46  		ctx.WriteString("s3option ")
    47  		formatS3option(ctx, node.Option)
    48  	} else {
    49  		ctx.WriteString("filesystem ")
    50  		ctx.WriteString(node.Dir)
    51  		ctx.WriteString(" parallelism ")
    52  		ctx.WriteString(node.Parallelism)
    53  	}
    54  
    55  	if node.BackupType != "" {
    56  		ctx.WriteString(" backuptype ")
    57  		ctx.WriteString(node.BackupType)
    58  	}
    59  
    60  	if node.BackupTs != "" {
    61  		ctx.WriteString(" backupts ")
    62  		ctx.WriteString(node.BackupTs)
    63  	}
    64  }
    65  
    66  func NewBackupStart(timestamp string, isS3 bool, dir string, parallelism string, option []string, backupType, backupTs string) *BackupStart {
    67  	backup := reuse.Alloc[BackupStart](nil)
    68  	backup.Timestamp = timestamp
    69  	backup.IsS3 = isS3
    70  	backup.Dir = dir
    71  	backup.Parallelism = parallelism
    72  	backup.Option = option
    73  	backup.BackupType = backupType
    74  	backup.BackupTs = backupTs
    75  	return backup
    76  }
    77  
    78  func (node *BackupStart) GetStatementType() string { return "Backup Start" }
    79  
    80  func (node *BackupStart) GetQueryType() string { return QueryTypeOth }
    81  
    82  func (node BackupStart) TypeName() string { return "tree.BackupStart" }
    83  
    84  func (node *BackupStart) reset() {
    85  	if node.Option != nil {
    86  		node.Option = nil
    87  	}
    88  	*node = BackupStart{}
    89  }
    90  
    91  func (node *BackupStart) Free() {
    92  	reuse.Free[BackupStart](node, nil)
    93  }