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 \ docker run \
-e "CAPTAIN_IS_DEBUG=1" \ -e "CAPTAIN_IS_DEBUG=1" \
-v /var/run/docker.sock:/var/run/docker.sock \ -v /var/run/docker.sock:/var/run/docker.sock \
-v /captain:/captain \
-v $(pwd):/usr/src/app captain-debug -v $(pwd):/usr/src/app captain-debug
sleep 2s sleep 2s
docker service logs captain-captain --follow docker service logs captain-captain --follow

View File

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