UNPKG

vmsnap

Version:

A Node based backup and backup rotation tool for KVM domains.

2 lines (1 loc) 1.37 kB
import{EOL as a}from"os";import{asyncExec as e}from"../vmsnap.js";import{logger as l}from"../vmsnap.js";export const VIRSH="virsh",CHECKPOINT_REGEX=/^virtnbdbackup\.[0-9]*$/;const d=async t=>{if(/^[A-Za-z0-9_\.\+\-&:/]*$/.test(t)===!1)return l.error(`Domain ${t} contains invalid characters`),!1;const n=[VIRSH,"domstate",t];try{return await e(n.join(" ")),!0}catch{return!1}},h=async()=>{const t=[VIRSH,"list","--all","--name"],{stdout:n,stderr:r}=await e(t.join(" "));if(r)throw new Error(r);return n.split(a).filter(o=>o.length>0)},f=async t=>{const n=[VIRSH,"checkpoint-list",t,"--name"],{stdout:r,stderr:o}=await e(n.join(" "));if(o)throw new Error(o);return r.split(a).filter(s=>s.trim()!=="")},p=async(t,n=void 0)=>{const r=await f(t);if(r.length!==0)for(const o of r){if(CHECKPOINT_REGEX.test(o)===!1||n&&o!==n)continue;const s=[VIRSH,"checkpoint-delete",t,o,"--metadata"];l.info(`Removing checkpoint ${o} from ${t}`);const{stderr:i}=await e(s.join(" "));if(i)throw new Error(i)}},u=async t=>{const n=new Map,r=[VIRSH,"domblklist",t,"--details"],{stdout:o,stderr:s}=await e(r.join(" "));if(s)throw new Error(s);for(const i of o.split(a).slice(1)){const c=i.split(" ").filter(m=>m.length>0);c.length>=4&&c[1]==="disk"&&n.set(c[2],c[3].trim())}return n};export{d as domainExists,h as fetchAllDomains,f as findCheckpoints,p as cleanupCheckpoints,u as fetchAllDisks};