yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/azure/rds_sqlserver_backup.go (about)

     1  // Copyright 2019 Yunion
     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 azure
    16  
    17  import (
    18  	"fmt"
    19  	"net/url"
    20  	"strings"
    21  	"time"
    22  
    23  	"yunion.io/x/pkg/errors"
    24  
    25  	api "yunion.io/x/cloudmux/pkg/apis/compute"
    26  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    27  	"yunion.io/x/cloudmux/pkg/multicloud"
    28  )
    29  
    30  type SSQLServerBackup struct {
    31  	rds *SSQLServer
    32  	multicloud.SDBInstanceBackupBase
    33  	AzureTags
    34  
    35  	ID         string `json:"id"`
    36  	Name       string `json:"name"`
    37  	Type       string `json:"type"`
    38  	Properties struct {
    39  		Servername              string    `json:"serverName"`
    40  		Servercreatetime        time.Time `json:"serverCreateTime"`
    41  		Databasename            string    `json:"databaseName"`
    42  		Databasedeletiontime    string    `json:"databaseDeletionTime"`
    43  		Backuptime              time.Time `json:"backupTime"`
    44  		Backupstorageredundancy string    `json:"backupStorageRedundancy"`
    45  	} `json:"properties"`
    46  }
    47  
    48  func (self *SSQLServerBackup) GetBackupMode() string {
    49  	return api.BACKUP_MODE_AUTOMATED
    50  }
    51  
    52  func (self *SSQLServerBackup) GetBackupMethod() cloudprovider.TBackupMethod {
    53  	return cloudprovider.BackupMethodUnknown
    54  }
    55  
    56  func (self *SSQLServerBackup) GetBackupSizeMb() int {
    57  	return 0
    58  }
    59  
    60  func (self *SSQLServerBackup) GetDBInstanceId() string {
    61  	return self.rds.GetGlobalId()
    62  }
    63  
    64  func (self *SSQLServerBackup) GetName() string {
    65  	return self.Name
    66  }
    67  
    68  func (self *SSQLServerBackup) GetDBNames() string {
    69  	return self.Properties.Databasename
    70  }
    71  
    72  func (self *SSQLServerBackup) GetStatus() string {
    73  	return api.DBINSTANCE_BACKUP_READY
    74  }
    75  
    76  func (self *SSQLServerBackup) GetId() string {
    77  	return self.ID
    78  }
    79  
    80  func (self *SSQLServerBackup) GetGlobalId() string {
    81  	return strings.ToLower(self.Name)
    82  }
    83  
    84  func (self *SSQLServerBackup) GetStartTime() time.Time {
    85  	return self.Properties.Backuptime
    86  }
    87  
    88  func (self *SSQLServerBackup) GetEndTime() time.Time {
    89  	return time.Time{}
    90  }
    91  
    92  func (self *SSQLServerBackup) GetEngine() string {
    93  	return self.rds.GetEngine()
    94  }
    95  
    96  func (self *SSQLServerBackup) GetEngineVersion() string {
    97  	return self.rds.GetEngineVersion()
    98  }
    99  
   100  func (self *SRegion) ListSQLServerBackups(id, location string) ([]SSQLServerBackup, error) {
   101  	ret := struct {
   102  		Value []SSQLServerBackup
   103  	}{}
   104  	r := fmt.Sprintf("Microsoft.Sql/locations/%s/longTermRetentionServers", location)
   105  	prefix := strings.Replace(strings.ToLower(id), "microsoft.sql/servers", r, -1)
   106  	return ret.Value, self.get(prefix+"/longTermRetentionBackups", url.Values{}, &ret)
   107  }
   108  
   109  func (self *SSQLServer) GetIDBInstanceBackups() ([]cloudprovider.ICloudDBInstanceBackup, error) {
   110  	backups, err := self.region.ListSQLServerBackups(self.ID, self.Location)
   111  	if err != nil {
   112  		return nil, errors.Wrapf(err, "ListSQLServerBackups")
   113  	}
   114  	ret := []cloudprovider.ICloudDBInstanceBackup{}
   115  	for i := range backups {
   116  		backups[i].rds = self
   117  		ret = append(ret, &backups[i])
   118  	}
   119  	return ret, nil
   120  }