EnVisageOnline/Main/Database/MaintenanceScripts/mongoDBBackup.ps1

17 lines
632 B
PowerShell

$basePath = "C:\data\mongo\backups";
$MongoPath="C:\Program Files\MongoDB\Server\3.0\bin\"
[Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" )
$date = Get-Date -UFormat %Y-%m-%d;
$backupFolder = $date;
$destinationPath = Join-Path $basePath $backupFolder;
$destinationFile = $basePath+"\"+$backupFolder+".zip"
cd $MongoPath
if(!(Test-Path -Path $destinationFile)) {
New-Item -ItemType directory -Path $destinationPath;
(.\mongodump.exe --out $destinationPath);
[System.IO.Compression.ZipFile]::CreateFromDirectory($destinationPath, $destinationFile)
Remove-Item $destinationPath -recurse
}