C
C#3y ago
The Don

Running MongoDump from C-Sharp Program in Linux Docker Container

Dear community, I am trying to write a Docker container that will automatically back up all my MongoDB data that's on another server. It should run mongodump on my MongoDb database (dbName) and then storing the archive as the designated file (mongoDumpPath). When I try to run this in C#, noting happens, (i.e. I can't see the archive file, the result string is empty). However, when I copy and paste the mongoDumpCommand string variable and paste it onto the bash shell of the container, it works perfectly.
// Create mongodump command.
var mongoDumpCommand = $"mongodump --uri=\"mongodb://{host}:{port}\" --db=\"{dbName}\" --archive=\"{mongoDumpPath}\"\r\n";

// Set the options of the process.
var startInfo = new ProcessStartInfo
{
FileName = "/bin/bash",
Arguments = mongoDumpCommand,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
};

var process = new Process
{
StartInfo = startInfo
};

// Start the process and wait for it to finish.
process.Start();
await process.WaitForExitAsync();

// Get the mongodump logs.
var result = await process.StandardOutput.ReadToEndAsync();
// Create mongodump command.
var mongoDumpCommand = $"mongodump --uri=\"mongodb://{host}:{port}\" --db=\"{dbName}\" --archive=\"{mongoDumpPath}\"\r\n";

// Set the options of the process.
var startInfo = new ProcessStartInfo
{
FileName = "/bin/bash",
Arguments = mongoDumpCommand,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
};

var process = new Process
{
StartInfo = startInfo
};

// Start the process and wait for it to finish.
process.Start();
await process.WaitForExitAsync();

// Get the mongodump logs.
var result = await process.StandardOutput.ReadToEndAsync();
Can you please advise? Thanks kindly! EDIT: The StandardError output shows an "unable to execute binary file" even though chmod +x /usr/bin/mongodump is in the Dockerfile.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server