7 if [ -z "$MONGO_HOST" ]; then
11 if [ -z "$MONGO_DB" ]; then
15 MONGO_URL
=$MONGO_HOST/$MONGO_DB
19 SCRIPT_DIR
="$( cd "$
( dirname "${BASH_SOURCE[0]}" )" && pwd )"
21 MD5
=$
(which md5||
which md5sum)
24 find $SCRIPT_DIR/dataupgrades
-type f
-name "*.sh" -print0 |
while read -d $
'\0' file
29 if [[ $
(mongo
$MONGO_URL --quiet --eval "print(db.dataUpgrades.find({ \"script\": \"$file\", \"md5\": \"$md5\"}).length())") -eq 0 ]]; then
30 if [[ "${SKIP_BACKUP}" != "yes" ]]; then
32 if [ -z "$BACKUP_DONE" ]; then
33 BACKUP_DIR
=mongo-backup-$
(date "+%Y-%m-%d.%H-%M-%S")
34 mkdir
-p "$BACKUP_DIR"
35 mongodump
--host $MONGO_HOST --oplog --out "mongo-backup-$(date "+%Y-
%m-
%d.
%H-
%M-
%S
")"
41 echo executing
"$file"
47 mongo
$MONGO_URL --quiet --eval "db.dataUpgradesExecutions.insert({ \"script\": \"$file\", \"md5\": \"$md5\", executedAt: new Date(), result: \"$result\"})"
49 if [ $result -eq 0 ]; then
50 mongo
$MONGO_URL --quiet --eval "db.dataUpgrades.update({ \"script\": \"$file\" }, { \"script\": \"$file\", \"md5\": \"$md5\", executedAt: new Date() }, { \"upsert\": true } )"