Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.cloud.agent.api.Command;
import com.cloud.agent.api.LogLevel;
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;

import java.util.List;

Expand All @@ -29,6 +30,7 @@ public class TakeBackupCommand extends Command {
private String backupPath;
private String backupRepoType;
private String backupRepoAddress;
private List<PrimaryDataStoreTO> volumePools;
private List<String> volumePaths;
private Boolean quiesce;
@LogLevel(LogLevel.Log4jLevel.Off)
Expand Down Expand Up @@ -80,6 +82,14 @@ public void setMountOptions(String mountOptions) {
this.mountOptions = mountOptions;
}

public List<PrimaryDataStoreTO> getVolumePools() {
return volumePools;
}

public void setVolumePools(List<PrimaryDataStoreTO> volumePools) {
this.volumePools = volumePools;
}

public List<String> getVolumePaths() {
return volumePaths;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ public Pair<Boolean, Backup> takeBackup(final VirtualMachine vm, Boolean quiesce
List<VolumeVO> vmVolumes = volumeDao.findByInstance(vm.getId());
vmVolumes.sort(Comparator.comparing(Volume::getDeviceId));
Pair<List<PrimaryDataStoreTO>, List<String>> volumePoolsAndPaths = getVolumePoolsAndPaths(vmVolumes);
List<String> volumePaths = volumePoolsAndPaths.second();
command.setVolumePaths(volumePaths);
command.setVolumePools(volumePoolsAndPaths.first());
command.setVolumePaths(volumePoolsAndPaths.second());
}

BackupAnswer answer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@
import com.amazonaws.util.CollectionUtils;
import com.cloud.agent.api.Answer;
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
import com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk;
import com.cloud.hypervisor.kvm.storage.KVMStoragePool;
import com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager;
import com.cloud.resource.CommandWrapper;
import com.cloud.resource.ResourceWrapper;
import com.cloud.storage.Storage;
import com.cloud.utils.Pair;
import com.cloud.utils.script.Script;
import org.apache.cloudstack.backup.BackupAnswer;
import org.apache.cloudstack.backup.TakeBackupCommand;
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -44,7 +49,22 @@ public Answer execute(TakeBackupCommand command, LibvirtComputingResource libvir
final String backupRepoType = command.getBackupRepoType();
final String backupRepoAddress = command.getBackupRepoAddress();
final String mountOptions = command.getMountOptions();
final List<String> diskPaths = command.getVolumePaths();
List<PrimaryDataStoreTO> volumePools = command.getVolumePools();
final List<String> volumePaths = command.getVolumePaths();
KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();

List<String> diskPaths = new ArrayList<>();
for (int idx = 0; idx < volumePaths.size(); idx++) {
PrimaryDataStoreTO volumePool = volumePools.get(idx);
Comment thread
sureshanaparti marked this conversation as resolved.
Outdated
String volumePath = volumePaths.get(idx);
if (volumePool.getPoolType() != Storage.StoragePoolType.RBD) {
diskPaths.add(volumePath);
} else {
KVMStoragePool volumeStoragePool = storagePoolMgr.getStoragePool(volumePool.getPoolType(), volumePool.getUuid());
String rbdDestVolumeFile = KVMPhysicalDisk.RBDStringBuilder(volumeStoragePool, volumePath);
diskPaths.add(rbdDestVolumeFile);
}
}

List<String[]> commands = new ArrayList<>();
commands.add(new String[]{
Expand Down
9 changes: 8 additions & 1 deletion scripts/vm/hypervisor/kvm/nasbackup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,14 @@ backup_stopped_vm() {

name="root"
for disk in $DISK_PATHS; do
volUuid="${disk##*/}"
if [[ "$disk" == rbd:* ]]; then
# disk for rbd => rbd:<pool>/<uuid>:mon_host=<monitor_host>...
# sample: rbd:cloudstack/53d5c355-d726-4d3e-9422-046a503a0b12:mon_host=10.0.1.2...
beforeUuid="${disk#*/}" # Remove up to first slash after rbd:
volUuid="${beforeUuid%%:*}" # Remove everything after colon to get the uuid
else
volUuid="${disk##*/}"
fi
output="$dest/$name.$volUuid.qcow2"
if ! qemu-img convert -O qcow2 "$disk" "$output" > "$logFile" 2> >(cat >&2); then
echo "qemu-img convert failed for $disk $output"
Expand Down
Loading