vitess.io/vitess@v0.16.2/go/vt/mysqlctl/mysqlctlproto/backup.go (about)

     1  /*
     2  Copyright 2021 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package mysqlctlproto
    18  
    19  import (
    20  	"vitess.io/vitess/go/protoutil"
    21  	"vitess.io/vitess/go/vt/mysqlctl"
    22  	"vitess.io/vitess/go/vt/mysqlctl/backupstorage"
    23  
    24  	mysqlctlpb "vitess.io/vitess/go/vt/proto/mysqlctl"
    25  )
    26  
    27  // BackupHandleToProto returns a BackupInfo proto from a BackupHandle.
    28  func BackupHandleToProto(bh backupstorage.BackupHandle) *mysqlctlpb.BackupInfo {
    29  	bi := &mysqlctlpb.BackupInfo{
    30  		Name:      bh.Name(),
    31  		Directory: bh.Directory(),
    32  	}
    33  
    34  	btime, alias, err := mysqlctl.ParseBackupName(bi.Directory, bi.Name)
    35  	if err != nil { // if bi.Name does not match expected format, don't parse any further fields
    36  		return bi
    37  	}
    38  
    39  	if btime != nil {
    40  		bi.Time = protoutil.TimeToProto(*btime)
    41  	}
    42  
    43  	bi.TabletAlias = alias
    44  
    45  	return bi
    46  }