$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;