Ejemplo n.º 1
0
    def run(self):
        logging.info("Starting mongodump (with oplog) backup of %s/%s:%i" %
                     (self.backup_name, self.host, self.port))

        mongodump_flags = [
            "-h", self.host_port, "--oplog", "-o",
            "%s/dump" % self.backup_dir
        ]
        if self.dump_gzip:
            logging.debug(
                "Enabling inline mongodump compression using --gzip flag")
            mongodump_flags.extend(["--gzip"])
        if self.authdb and self.authdb != "admin":
            logging.debug("Using database %s for authentication" % self.authdb)
            mongodump_flags.extend(["--authenticationDatabase", self.authdb])
        if self.user and self.password:
            mongodump_flags.extend(["-u", self.user, "-p", self.password])

        try:
            commands = []
            if os.path.isdir(self.dump_dir):
                commands.append(["rm", ["-rf", self.dump_dir]])
            commands.append(["mkdir", ["-p", self.dump_dir]])
            commands.append([self.binary, mongodump_flags])

            for (command, command_flags) in commands:
                self._command = LocalCommand(command, command_flags,
                                             self.verbose)
                self._command.run()
        except Exception, e:
            logging.error("Error performing mongodump: %s" % e)
            return None