Skip to content

Instantly share code, notes, and snippets.

@adrianvlupu
Created November 5, 2017 09:54
Show Gist options
  • Save adrianvlupu/c11ae686907dd53b0b5ac3278af28c38 to your computer and use it in GitHub Desktop.
Save adrianvlupu/c11ae686907dd53b0b5ac3278af28c38 to your computer and use it in GitHub Desktop.
$date = Get-Date -UFormat %Y-%m-%d;
$backupFolder = $date;
$basePath = 'C:\projects\db-backups';
$destinationPath = Join-Path $basePath $backupFolder;
$mongodumpPath = 'C:\Program Files\MongoDB\Server\3.4\bin\mongodump.exe';
Write-Host "
Your backup parameters are:
mongodump: $mongodumpPath
output: $basePath
";
$shouldChangeOutputBit = Read-Host -Prompt 'Change the output base path ? (Y/N)';
if ($shouldChangeOutputBit -eq 'Y' ) {
$basePath = Read-Host -Prompt 'Enter the new backup path';
$destinationPath = Join-Path $basePath $backupFolder;
Write-Host "
Your NEW output path is: $basePath";
}
if (!(Test-Path -Path $destinationPath)) {
New-Item -ItemType directory -Path $destinationPath;
}
& $mongodumpPath --out $destinationPath;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment