Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean DB and check files #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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]} \
Expand All @@ -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]} \
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions workflow/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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',
Expand All @@ -58,7 +58,8 @@ const migrate = (deploymentConfig, api, log) =>
],
failMessages: [
'MIGRATION FAILED'
]
],
startTimeout: 3600
};
}));
}, 'migration.oldServices', 'migration.apps')
Expand All @@ -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'
}
};
}));
Expand Down