From ff01def735ededa868fe34c287489b42f97de58e Mon Sep 17 00:00:00 2001 From: Micha Schwendener Date: Fri, 27 Apr 2018 23:40:49 +0200 Subject: [PATCH] Clean DB and check files --- migrate.sh | 38 ++++++++++++++++++++++++++++++++++---- workflow/migrate.js | 10 ++++++---- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/migrate.sh b/migrate.sh index 826d8d2..0ea2527 100755 --- a/migrate.sh +++ b/migrate.sh @@ -96,6 +96,10 @@ echo "" if [[ -n ${DEBUG} ]] ; then echo "Going to execute the following command: + +mongo ${to[uri]} \ + --eval 'db.dropDatabase()' + mongodump --host ${from[host]} \ --db ${from[database]} \ ${from[port_line]} \ @@ -113,6 +117,10 @@ mongorestore --host ${to[host]} \ --nsTo=${to[database]}.* " fi + +mongo ${to[uri]} \ + --eval 'db.dropDatabase()' + mongodump --host ${from[host]} \ --db ${from[database]} \ ${from[port_line]} \ @@ -128,12 +136,34 @@ mongorestore --host ${to[host]} \ --archive \ --nsFrom=${from[database]}.* \ --nsTo=${to[database]}.* + + + +sourceDb="$(mongo ${from[database]} --host ${from[host]} \ + ${from[port_line]} \ + --authenticationDatabase ${from[database]} \ + --username ${from[username]} \ + --password ${from[password]} \ + --eval 'db.getCollectionNames().reduce(function(acc, c) { if (c.indexOf("system.") == -1) { return acc + db[c].count(); } return acc }, 0)' \ + --quiet)" + +targetDb="$(mongo ${to[uri]} \ + --eval 'db.getCollectionNames().reduce(function(acc, c) { if (c.indexOf("system.") == -1) { return acc + db[c].count(); } return acc }, 0)' \ + --quiet | grep -e '^[0-9][0-9]*$')" + + +dbsizesame=0 + +if [ "$sourceDb" != "$targetDb" ]; then + dbsizesame=1 +fi + RC=$? -echo "Finished mongodb Migration with RC: $?" -if [[ ${RC} -eq 0 ]]; then - echo "MIGRATION SUCCESSFULL" +echo "Finished redis Migration with RC: $?" +if [[ ${RC} -eq 0 && ${dbsizesame} -eq 0 ]]; then + echo "MIGRATION SUCCESSFULL" else - echo "MIGRATION FAILED" + echo "MIGRATION FAILED" fi while true ; do diff --git a/workflow/migrate.js b/workflow/migrate.js index a2b7c8c..e70b65f 100644 --- a/workflow/migrate.js +++ b/workflow/migrate.js @@ -15,7 +15,7 @@ const migrate = (deploymentConfig, api, log) => , step(log('preparing local data structures')) , step( - (services, cb) => cb(null, _.filter(services, (service) => service.type === (process.env.OLD_SERVICE_TYPE_NAME || 'mongodb'))) + (services, cb) => cb(null, _.filter(services, (service) => (service.type === (process.env.OLD_SERVICE_TYPE_NAME || 'mongodb')))) , 'current.services' , 'migration.oldServices') @@ -47,9 +47,9 @@ const migrate = (deploymentConfig, api, log) => return { name: `migrate-${service.name}`, disk: '512M', - memory: '256M', + memory: '2048M', instances: 1, - health_check_type: 'none', + healthCheckType: 'process', diego: true, enable_ssh: true, dockerImage: 'push2cloud/migrate-mongodb:1.1.0', @@ -58,7 +58,8 @@ const migrate = (deploymentConfig, api, log) => ], failMessages: [ 'MIGRATION FAILED' - ] + ], + startTimeout: 3600 }; })); }, 'migration.oldServices', 'migration.apps') @@ -72,6 +73,7 @@ const migrate = (deploymentConfig, api, log) => toService: `${service.name}-new`, "OLD_SERVICE_TYPE_NAME": process.env.OLD_SERVICE_TYPE_NAME || 'mongodb', "NEW_SERVICE_TYPE_NAME": process.env.NEW_SERVICE_TYPE_NAME || 'mongodb', + "DEBUG": 'true' } }; }));