Updated backup

This commit is contained in:
Kasra Bigdeli
2019-02-21 21:55:13 -08:00
parent 3d58fc7351
commit b9e5c65dd4
2 changed files with 110 additions and 122 deletions

View File

@@ -15,6 +15,7 @@ chmod -R 777 /captain
docker run \
-e "CAPTAIN_IS_DEBUG=1" \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /captain:/captain \
-v $(pwd):/usr/src/app captain-debug
sleep 2s
docker service logs captain-captain --follow

View File

@@ -64,14 +64,14 @@ export default class BackupManager {
const oldNodeIdToNewIpMap: IHashMapGeneric<string> = {}
return Promise.resolve()
.then(function() {
if (!fs.pathExistsSync(RESTORE_INSTRUCTIONS_ABS_PATH)) return
return Promise.resolve()
.then(function() {
Logger.d('Starting restoration, PHASE 1.')
return fs
.readJson(RESTORE_INSTRUCTIONS_ABS_PATH)
return fs.readJson(RESTORE_INSTRUCTIONS_ABS_PATH)
})
.then(function(restoringInfo: RestoringInfo) {
const ps: (() => Promise<void>)[] = []
restoringInfo.nodesMapping.forEach(n => {
@@ -81,8 +81,7 @@ export default class BackupManager {
restoringInfo.oldNodesForReference.forEach(oldN => {
if (oldN.nodeData.ip === n.oldIp) {
oldNodeIdToNewIpMap[oldN.nodeData.nodeId] =
n.newIp
oldNodeIdToNewIpMap[oldN.nodeData.nodeId] = n.newIp
if (oldN.nodeData.type === 'manager') {
isManager = true
}
@@ -96,18 +95,14 @@ export default class BackupManager {
return Promise.resolve()
.then(function() {
Logger.d(
'Joining other node to swarm: ' +
NEW_IP
'Joining other node to swarm: ' + NEW_IP
)
return DockerUtils.joinDockerNode(
DockerApi.get(),
captainIpAddress,
isManager,
NEW_IP,
fs.readFileSync(
PRIVATE_KEY_PATH,
'utf8'
)
fs.readFileSync(PRIVATE_KEY_PATH, 'utf8')
)
})
.then(function() {
@@ -121,9 +116,7 @@ export default class BackupManager {
return Utils.runPromises(ps)
})
.then(function() {
Logger.d(
'Waiting for 5 seconds for things to settle...'
)
Logger.d('Waiting for 5 seconds for things to settle...')
return Utils.getDelayedPromise(5000)
})
.then(function() {
@@ -152,26 +145,19 @@ export default class BackupManager {
Object.keys(oldNodeIdToNewIpMap).forEach(oldNodeId => {
const newIp = oldNodeIdToNewIpMap[oldNodeId]
Object.keys(configData.appDefinitions).forEach(
appName => {
Object.keys(configData.appDefinitions).forEach(appName => {
if (
configData.appDefinitions[appName]
.nodeId === oldNodeId
configData.appDefinitions[appName].nodeId ===
oldNodeId
) {
configData.appDefinitions[
appName
].nodeId = newIp
configData.appDefinitions[appName].nodeId = newIp
? getNewNodeIdForIp(newIp)
: '' // If user removed new IP, it will mean that the user is okay with this node being automatically assigned to a node ID
}
}
)
})
})
return fs.outputJson(
configFilePathRestoring,
configData
)
return fs.outputJson(configFilePathRestoring, configData)
})
.then(function() {
Logger.d('Config remapping done.')
@@ -198,7 +184,6 @@ export default class BackupManager {
CaptainConstants.captainDataDirectory
)
})
})
.then(function() {
Logger.d('Restoration Phase#1 is completed!')
})
@@ -254,8 +239,10 @@ export default class BackupManager {
const self = this
return Promise.resolve() //
.then(function() {
if (!fs.pathExistsSync(CaptainConstants.restoreTarFilePath))
if (!fs.pathExistsSync(CaptainConstants.restoreTarFilePath)) {
Logger.d('Fresh installation!')
return false
}
Logger.d('Backup file found! Starting restoration process...')