forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backup: simple NAS backup plugin for KVM (apache#9451)
This is a simple NAS backup plugin for KVM which may be later expanded for other hypervisors. This backup plugin aims to use shared NAS storage on KVM hosts such as NFS (or CephFS and others in future), which is used to backup fully cloned VMs for backup & restore operations. This may NOT be as efficient and performant as some of the other B&R providers, but maybe useful for some KVM environments who are okay to only have full-instance backups and limited functionality. Design & Implementation follows the `networker` B&R plugin, which is simply: - Implement B&R plugin interfaces - Use cmd-answer pattern to execute backup and restore operations on KVM host when VM is running (or needs to be restored) - instead of a B&R API client, relies on answers from KVM agent which executes the operations - Backups are full VM domain snapshots, copied to a VM-specific folders on a NAS target (NFS) along with a domain XML - Backup uses libvirt feature: https://libvirt.org/kbase/live_full_disk_backup.html orchestrated via virsh/bash script (nasbackup.sh) as the libvirt-java lacks the bindings - Supported instance volume storage for restore operations: NFS & local storage Refer the doc PR for feature limitations and usage details: apache/cloudstack-documentation#429 Signed-off-by: Rohit Yadav <[email protected]> Co-authored-by: Pearl Dsilva <[email protected]> Co-authored-by: Abhishek Kumar <[email protected]> Co-authored-by: Suresh Kumar Anaparti <[email protected]>
- Loading branch information
1 parent
c3f0d14
commit 85765c3
Showing
59 changed files
with
2,735 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
...java/org/apache/cloudstack/api/command/user/backup/repository/AddBackupRepositoryCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.cloudstack.api.command.user.backup.repository; | ||
|
||
import org.apache.cloudstack.acl.RoleType; | ||
import org.apache.cloudstack.api.APICommand; | ||
import org.apache.cloudstack.api.ApiConstants; | ||
import org.apache.cloudstack.api.ApiErrorCode; | ||
import org.apache.cloudstack.api.BaseCmd; | ||
import org.apache.cloudstack.api.Parameter; | ||
import org.apache.cloudstack.api.ServerApiException; | ||
import org.apache.cloudstack.api.response.BackupRepositoryResponse; | ||
import org.apache.cloudstack.api.response.ZoneResponse; | ||
import org.apache.cloudstack.backup.BackupRepository; | ||
import org.apache.cloudstack.backup.BackupRepositoryService; | ||
import org.apache.cloudstack.context.CallContext; | ||
|
||
import javax.inject.Inject; | ||
|
||
@APICommand(name = "addBackupRepository", | ||
description = "Adds a backup repository to store NAS backups", | ||
responseObject = BackupRepositoryResponse.class, since = "4.20.0", | ||
authorized = {RoleType.Admin}) | ||
public class AddBackupRepositoryCmd extends BaseCmd { | ||
|
||
@Inject | ||
private BackupRepositoryService backupRepositoryService; | ||
|
||
///////////////////////////////////////////////////// | ||
//////////////// API parameters ///////////////////// | ||
///////////////////////////////////////////////////// | ||
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "name of the backup repository") | ||
private String name; | ||
|
||
@Parameter(name = ApiConstants.ADDRESS, type = CommandType.STRING, required = true, description = "address of the backup repository") | ||
private String address; | ||
|
||
@Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, required = true, description = "type of the backup repository storage. Supported values: nfs, cephfs, cifs") | ||
private String type; | ||
|
||
@Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, description = "backup repository provider") | ||
private String provider; | ||
|
||
@Parameter(name = ApiConstants.MOUNT_OPTIONS, type = CommandType.STRING, description = "shared storage mount options") | ||
private String mountOptions; | ||
|
||
@Parameter(name = ApiConstants.ZONE_ID, | ||
type = CommandType.UUID, | ||
entityType = ZoneResponse.class, | ||
required = true, | ||
description = "ID of the zone where the backup repository is to be added") | ||
private Long zoneId; | ||
|
||
@Parameter(name = ApiConstants.CAPACITY_BYTES, type = CommandType.LONG, description = "capacity of this backup repository") | ||
private Long capacityBytes; | ||
|
||
|
||
///////////////////////////////////////////////////// | ||
/////////////////// Accessors /////////////////////// | ||
///////////////////////////////////////////////////// | ||
|
||
public BackupRepositoryService getBackupRepositoryService() { | ||
return backupRepositoryService; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getType() { | ||
if ("cephfs".equalsIgnoreCase(type)) { | ||
return "ceph"; | ||
} | ||
return type.toLowerCase(); | ||
} | ||
|
||
public String getAddress() { | ||
return address; | ||
} | ||
|
||
public String getProvider() { | ||
return provider; | ||
} | ||
|
||
public String getMountOptions() { | ||
return mountOptions == null ? "" : mountOptions; | ||
} | ||
|
||
public Long getZoneId() { | ||
return zoneId; | ||
} | ||
|
||
public Long getCapacityBytes() { | ||
return capacityBytes; | ||
} | ||
|
||
///////////////////////////////////////////////////// | ||
/////////////////// Accessors /////////////////////// | ||
///////////////////////////////////////////////////// | ||
|
||
@Override | ||
public void execute() { | ||
try { | ||
BackupRepository result = backupRepositoryService.addBackupRepository(this); | ||
if (result != null) { | ||
BackupRepositoryResponse response = _responseGenerator.createBackupRepositoryResponse(result); | ||
response.setResponseName(getCommandName()); | ||
this.setResponseObject(response); | ||
} else { | ||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add backup repository"); | ||
} | ||
} catch (Exception ex4) { | ||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex4.getMessage()); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public long getEntityOwnerId() { | ||
return CallContext.current().getCallingAccount().getId(); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...a/org/apache/cloudstack/api/command/user/backup/repository/DeleteBackupRepositoryCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.cloudstack.api.command.user.backup.repository; | ||
|
||
import org.apache.cloudstack.acl.RoleType; | ||
import org.apache.cloudstack.api.APICommand; | ||
import org.apache.cloudstack.api.ApiConstants; | ||
import org.apache.cloudstack.api.ApiErrorCode; | ||
import org.apache.cloudstack.api.BaseCmd; | ||
import org.apache.cloudstack.api.Parameter; | ||
import org.apache.cloudstack.api.ServerApiException; | ||
import org.apache.cloudstack.api.response.BackupRepositoryResponse; | ||
import org.apache.cloudstack.api.response.SuccessResponse; | ||
import org.apache.cloudstack.backup.BackupRepositoryService; | ||
|
||
import javax.inject.Inject; | ||
|
||
@APICommand(name = "deleteBackupRepository", | ||
description = "delete a backup repository", | ||
responseObject = SuccessResponse.class, since = "4.20.0", | ||
authorized = {RoleType.Admin}) | ||
public class DeleteBackupRepositoryCmd extends BaseCmd { | ||
|
||
@Inject | ||
BackupRepositoryService backupRepositoryService; | ||
|
||
///////////////////////////////////////////////////// | ||
//////////////// API parameters ///////////////////// | ||
///////////////////////////////////////////////////// | ||
@Parameter(name = ApiConstants.ID, | ||
type = CommandType.UUID, | ||
entityType = BackupRepositoryResponse.class, | ||
required = true, | ||
description = "ID of the backup repository to be deleted") | ||
private Long id; | ||
|
||
|
||
///////////////////////////////////////////////////// | ||
//////////////// Accessors ////////////////////////// | ||
///////////////////////////////////////////////////// | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
boolean result = backupRepositoryService.deleteBackupRepository(this); | ||
if (result) { | ||
SuccessResponse response = new SuccessResponse(getCommandName()); | ||
this.setResponseObject(response); | ||
} else { | ||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete backup repository"); | ||
} | ||
} | ||
|
||
@Override | ||
public long getEntityOwnerId() { | ||
return 0; | ||
} | ||
} |
Oops, something went wrong.