feat(xo-server/backupNg): support restoring directories (#3300)
See #1924
This commit is contained in:
parent
4a1e87b534
commit
e7467dca8a
@ -34,12 +34,30 @@ const PARTITION_TYPE_NAMES = {
|
|||||||
|
|
||||||
const RE_VHDI = /^vhdi(\d+)$/
|
const RE_VHDI = /^vhdi(\d+)$/
|
||||||
|
|
||||||
|
async function addDirectory (zip, realPath, metadataPath) {
|
||||||
|
try {
|
||||||
|
const files = await readdir(realPath)
|
||||||
|
await Promise.all(
|
||||||
|
files.map(file =>
|
||||||
|
addDirectory(zip, realPath + '/' + file, metadataPath + '/' + file)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} catch (error) {
|
||||||
|
if (error == null || error.code !== 'ENOTDIR') {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
zip.addFile(realPath, metadataPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const parsePartxLine = createPairsParser({
|
const parsePartxLine = createPairsParser({
|
||||||
keyTransform: key => (key === 'UUID' ? 'id' : key.toLowerCase()),
|
keyTransform: key => (key === 'UUID' ? 'id' : key.toLowerCase()),
|
||||||
valueTransform: (value, key) =>
|
valueTransform: (value, key) =>
|
||||||
key === 'start' || key === 'size'
|
key === 'start' || key === 'size'
|
||||||
? +value
|
? +value
|
||||||
: key === 'type' ? PARTITION_TYPE_NAMES[+value] || value : value,
|
: key === 'type'
|
||||||
|
? PARTITION_TYPE_NAMES[+value] || value
|
||||||
|
: value,
|
||||||
})
|
})
|
||||||
|
|
||||||
const listLvmLogicalVolumes = defer(
|
const listLvmLogicalVolumes = defer(
|
||||||
@ -163,7 +181,11 @@ export default class BackupNgFileRestore {
|
|||||||
|
|
||||||
const zip = new ZipFile()
|
const zip = new ZipFile()
|
||||||
paths.forEach(file => {
|
paths.forEach(file => {
|
||||||
zip.addFile(resolveSubpath(partition.path, file), normalize('./' + file))
|
addDirectory(
|
||||||
|
zip,
|
||||||
|
resolveSubpath(partition.path, file),
|
||||||
|
normalize('./' + file)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
zip.end()
|
zip.end()
|
||||||
return zip.outputStream.on('end', () =>
|
return zip.outputStream.on('end', () =>
|
||||||
|
Loading…
Reference in New Issue
Block a user