Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Updated "local" DB option to if case #9

Open
wants to merge 3 commits 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
16 changes: 7 additions & 9 deletions src/main/groovy/com/ee/tayra/command/backup/Backup.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@
* official policies, either expressed or implied, of the Tayra Project.
******************************************************************************/
package com.ee.tayra.command.backup

import groovy.json.JsonSlurper

import org.bson.types.BSONTimestamp

import com.ee.tayra.connector.MongoAuthenticator
import com.ee.tayra.connector.MongoReplSetConnection
import com.ee.tayra.domain.*
import com.ee.tayra.io.*
import com.ee.tayra.domain.Oplog
import com.ee.tayra.io.Copier
import groovy.json.JsonSlurper
import org.bson.types.BSONTimestamp

def cli = new CliBuilder(usage:'backup -s <MongoDB> [--port=number] -f <file> [--fSize=BackupFileSize] [--fMax=NumberOfRotatingLogs] [-t] [-u username] [-p password] [--sNs=<dbName>]')
cli.with {
Expand Down Expand Up @@ -165,6 +162,7 @@ try {
}
} catch (Throwable problem) {
console.println "Oops!! Could not perform backup...$problem.message"
Runtime.getRuntime().exit(1);
} finally {
reader?.close()
timestampRecorder.stop()
Expand All @@ -184,8 +182,8 @@ private printTimestampCaution(timestampRecorder, PrintWriter console) {
}
else {
def timestampJson = new JsonSlurper().parseText(timestamp)
Integer time = timestampJson['ts']['$timestamp']['t']
Integer inc = timestampJson['ts']['$timestamp']['i']
Integer time = timestampJson['ts']['$ts']
Integer inc = timestampJson['ts']['$inc']
def bsonTime = new BSONTimestamp(time, inc)
console.println "Backup is starting from: \n $bsonTime ==> (${timestamp})"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
* official policies, either expressed or implied, of the Tayra Project.
******************************************************************************/
package com.ee.tayra.connector

import com.mongodb.CommandFailureException
import com.mongodb.MongoClient
import com.mongodb.MongoException
import com.mongodb.MongoSocketException

class MongoAuthenticator implements Authenticator {

Expand Down Expand Up @@ -67,7 +65,9 @@ class MongoAuthenticator implements Authenticator {
throw new MongoException('Password cannot be empty')
}
if(!mongo.getDB('admin').authenticate(username, password.toCharArray())) {
throw new MongoException("Authentication Failed to $mongo.address.host")
if (!mongo.getDB('local').authenticate(username, password.toCharArray())) {
throw new MongoException("Authentication Failed to $mongo.address.host")
}
}
true
}
Expand Down