-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstorage.ts
More file actions
49 lines (40 loc) · 1.59 KB
/
Copy pathstorage.ts
File metadata and controls
49 lines (40 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { zip } from './zip';
import { writeFileSync } from 'fs';
import { octoberDir } from './get-config';
import { resolve } from 'path';
import { execSync } from 'child_process';
const extract = require('extract-zip');
export const backupStorage = (zipToFile: string) => {
return zip('storage', zipToFile);
};
/**
* We are not using 'fs' methods for deleting and moving large directories here,
* because the yarn pnp re-implementations of these have a bug with file paths:
* https://github.com/yarnpkg/berry/issues/1818
**/
export const restoreStorage = async (dir: string) => {
const archivePath = resolve(octoberDir, 'backups', dir, 'storage.zip');
const extractPath = resolve(octoberDir, 'backups', dir, 'storage');
const storagePath = resolve(octoberDir, 'storage');
/*
* Make sure the temporary extract path does not contain leftovers from a
* previous failed attempt.
*/
console.log('... cleaning extract path');
execSync(`rm -rf ${extractPath}`);
console.log('... extracting storage from backup');
try {
await extract(archivePath, { dir: extractPath });
} catch (err) {
console.error(`Extraction failed for ${archivePath} => ${extractPath}`);
console.log('... cleaning extract path');
execSync(`rm -rf ${extractPath}`);
throw err;
}
console.log('... removing old storage dir');
execSync(`rm -rf ${storagePath}`);
console.log('... moving extracted storage to storage dir');
execSync(`mv ${extractPath} ${storagePath}`);
// Mark the fresh backup as the current one.
writeFileSync(resolve(octoberDir, 'backups', '.current.storage'), dir);
}