Skip to content

Instantly share code, notes, and snippets.

@goyalmohit
Created February 11, 2018 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goyalmohit/bb9164a8e35fb0bd242acf4cf1eb619c to your computer and use it in GitHub Desktop.
Save goyalmohit/bb9164a8e35fb0bd242acf4cf1eb619c to your computer and use it in GitHub Desktop.
$cosmosServer = "mycosmos.documents.azure.com:10255" #Define the cosmos db hostname and port
$cosmosUser = "mycosmos-username" #Define username
$cosmosPassword = "mycosmos-password" #Defines password
$backupDir = "C:\cosmos-backup\$(Get-Date -Format yyyyMMddhhmmss)"
if(!(Test-Path $backupDir)){
Write-Host "Creating temporary backup directory as $backupDir"
New-Item -Path $backupDir -ItemType Directory | Out-Null
}
Set-Location $backupDir
$mongoExe = "C:\Program Files\MongoDB\Server\3.6\bin\mongodump.exe"
$arguments = "--host $cosmosServer -u $cosmosUser -p $cosmosPassword --ssl --sslAllowInvalidCertificates --out $backupDir -vvvvv"
Start-Process $mongoExe $arguments -Wait -RedirectStandardError "standarderror.txt" -RedirectStandardOutput "standardoutput.txt"
Write-Host "Displaying standard output:"
Get-Content "standardoutput.txt"
Write-Host "Displaying if any errors:"
Get-Content "standarderror.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment