-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtugboat-restore.js
48 lines (40 loc) · 1.55 KB
/
tugboat-restore.js
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
const { execSync } = require('child_process')
const path = require('path')
const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
rl.question('Enter Docker image names to restore (separated by a comma): ', (imageAnswer) => {
const images = imageAnswer.split(',').map(img => img.trim()).filter(img => img)
rl.question('Enter Docker volume names to restore (separated by a comma): ', (volumeAnswer) => {
const volumes = volumeAnswer.split(',').map(vol => vol.trim()).filter(vol => vol)
restoreDocker(images, volumes)
rl.close()
})
})
function restoreDocker (images, volumes) {
console.log('Restoring images:', images)
console.log('Restoring volumes:', volumes)
const restoreDir = process.argv[2] || './backup' // You can pass the restore directory as an argument
// Restore Docker Images
images.forEach(image => {
const imagePath = path.join(restoreDir, `${image}.tar`)
console.log(`Restoring Docker image: ${image}`)
try {
execSync(`docker load -i "${imagePath}"`)
} catch (error) {
console.error(`Error restoring image ${image}:`, error)
}
})
// Restore Docker Volumes
volumes.forEach(volume => {
console.log(`Restoring Docker volume: ${volume}`)
try {
execSync(`docker run --rm -v ${volume}:/volume -v ${restoreDir}:/backup alpine tar xvf /backup/${volume}.tar -C /volume`)
} catch (error) {
console.error(`Error restoring volume ${volume}:`, error)
}
})
console.log('Restore completed successfully.')
}