@xiaoyuyu6420/dsh-backup 0.13.1 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +6 -1
- package/README.md +8 -1
- package/lib/client.js +2 -2
- package/lib/index.js +292 -78
- package/package.json +8 -8
- package/rescue/rescue.mjs +10 -6
package/rescue/rescue.mjs
CHANGED
|
@@ -108,7 +108,7 @@ async function listBackups(root) {
|
|
|
108
108
|
}
|
|
109
109
|
const backups = [];
|
|
110
110
|
for (const d of dirents) {
|
|
111
|
-
if (!d.name.startsWith('dsh-') || d.name.startsWith('dsh-pre-restore-') || d.name.startsWith('dsh-t-') || !d.name.endsWith('.tar.gz')) continue;
|
|
111
|
+
if (!d.name.startsWith('dsh-') || d.name.startsWith('dsh-pre-restore-') || d.name.startsWith('dsh-pre-upgrade-') || d.name.startsWith('dsh-t-') || !d.name.endsWith('.tar.gz')) continue;
|
|
112
112
|
let size;
|
|
113
113
|
try {
|
|
114
114
|
size = (await fs.stat(`${root}/${d.name}`)).size;
|
|
@@ -610,23 +610,27 @@ const show = (r) => {
|
|
|
610
610
|
const log = (t) => { document.getElementById('log').textContent = typeof t === 'string' ? t : show(t); };
|
|
611
611
|
const dlg = document.getElementById('confirm');
|
|
612
612
|
const fmtSize = (n) => typeof n !== 'number' ? '?' : n >= 1048576 ? (n/1048576).toFixed(1) + 'MB' : Math.max(1, Math.round(n/1024)) + 'KB';
|
|
613
|
+
const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
613
614
|
async function api(op, body) {
|
|
614
615
|
const res = await fetch('/api/' + op, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Dsh-Rescue': '1' }, body: JSON.stringify(body || {}) });
|
|
615
616
|
return res.json();
|
|
616
617
|
}
|
|
618
|
+
let listNames = [];
|
|
617
619
|
async function renderList() {
|
|
618
620
|
const r = await api('list');
|
|
619
621
|
if (!r.ok) { log(r); return; }
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
'
|
|
622
|
+
listNames = r.backups.map(b => b.name);
|
|
623
|
+
const rows = r.backups.map((b, i) => '<tr><td>' + esc(b.name) + '</td><td>' + fmtSize(b.size) +
|
|
624
|
+
'</td><td><button onclick="verify(' + i + ')">校验</button> ' +
|
|
625
|
+
'<button class="danger" onclick="restore(' + i + ')">恢复…</button></td></tr>').join('');
|
|
623
626
|
document.getElementById('list').innerHTML = r.backups.length
|
|
624
627
|
? '<table><tr><th>备份</th><th>大小</th><th></th></tr>' + rows + '</table>'
|
|
625
628
|
: '<p>备份目录里没有找到归档。</p>';
|
|
626
629
|
log(r.summary || '');
|
|
627
630
|
}
|
|
628
|
-
async function verify(
|
|
629
|
-
async function restore(
|
|
631
|
+
async function verify(i) { log(await api('verify', { selector: listNames[i] })); }
|
|
632
|
+
async function restore(i) {
|
|
633
|
+
const name = listNames[i];
|
|
630
634
|
const pre = await api('restore', { selector: name, dryRun: true });
|
|
631
635
|
log(pre);
|
|
632
636
|
if (!pre.ok) return;
|