Created
February 5, 2014 02:09
-
-
Save mxrss/8816312 to your computer and use it in GitHub Desktop.
Move Enviroment Build Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$enum = " | |
namespace Deployment | |
{ | |
public enum Enviroment{ | |
Dev, | |
QA, | |
Integration | |
} | |
} | |
" | |
if (-not ("Deployment.Enviroment" -as [type])){ | |
Add-Type -TypeDefinition $enum -Language CSharpVersion3 | |
} | |
$devKeys = @{WebPath="D:\Playground\Dev\";ExePath="D:\Playground\DevTest"} | |
$qaKeys = @{WebPath="D:\Playground\QA\";ExePath="D:\Playground\Dev-QA"} | |
$integrationKeys = @{WebPath="D:\Playground\Integration";ExePath="D:\Playground\Dev-Integration"} | |
$dev = new-object psobject -Property $devKeys | |
$qa = new-object psobject -Property $qaKeys | |
$integration = New-Object psobject $integrationKeys | |
$enviroments = @{[Deployment.Enviroment]::Dev=$dev; | |
[Deployment.Enviroment]::QA=$qa; | |
[Deployment.Enviroment]::Integration=$integration} | |
$exclusions = @("*.config", "Logs"); | |
$archiveDir = "D:\Backups" | |
function Move-Build | |
{ | |
Param( | |
[Parameter(Mandatory=$true)] | |
[Deployment.Enviroment]$FromEnviroment, | |
[Parameter(Mandatory=$true)] | |
[Deployment.Enviroment]$ToEnviroment, | |
[Parameter(Mandatory=$false)] | |
[switch]$Backup | |
) | |
if ($FromEnviroment -gt $ToEnviroment){ | |
throw "Can not move a build that is older to a downlevel enviroment, use last restore" | |
} | |
if ($FromEnviroment -eq $ToEnviroment){ | |
throw "Can not move a bulid to an existing build level" | |
} | |
if ($Backup.IsPresent){ | |
$todaysDate = $(get-date).ToString("yyyy.MM.dd.fffff") | |
if ($(test-path -Path "$archiveDir\$ToEnviroment") -eq $false){ | |
mkdir -Path "$archiveDir\$ToEnviroment" | |
} | |
Write-ArchiveFile -ZipFileName "$archiveDir\$ToEnviroment\Web-$todaysDate.zip" -SourceDirectory $enviroments[$ToEnviroment].WebPath | |
Write-ArchiveFile -ZipFileName "$archiveDir\$ToEnviroment\App-$todaysDate.zip" -SourceDirectory $enviroments[$ToEnviroment].ExePath | |
} | |
#$filesToCopy = Get-ChildItem -Path $enviroments[$FromEnviroment].WebPath -Exclude $exclusions -Recurse | |
$copyPath = [System.IO.Path]::Combine($enviroments[$FromEnviroment].WebPath, "*"); | |
$delPath = [System.IO.Path]::Combine($enviroments[$ToEnviroment].WebPath, "*") | |
Remove-Item $delPath -Exclude $exclusions -Recurse | |
Copy-Item $copyPath $enviroments[$ToEnviroment].WebPath -Exclude $exclusions -Recurse | |
$copyPath = [System.IO.Path]::Combine($enviroments[$FromEnviroment].ExePath, "*") | |
$delPath = [System.IO.Path]::Combine($enviroments[$ToEnviroment].ExePath, "*") | |
Remove-Item $delPath -Exclude $exclusions -Recurse | |
Copy-Item $copyPath $enviroments[$ToEnviroment].ExePath -Exclude $exclusions -Recurse | |
# post file rename on exepath | |
$pathToExe = Get-ChildItem $enviroments[$ToEnviroment].ExePath -filter "*.exe" | |
Rename-Item $pathToExe[0].FullName -NewName "$ToEnviroment.TMZ.Middleware.MessageProcessor.exe" | |
} | |
function Write-ArchiveFile | |
{ | |
Param( | |
[Parameter(Mandatory=$true)] | |
[string]$ZipFileName, | |
[Parameter(Mandatory=$true)] | |
[string]$SourceDirectory, | |
[Parameter(Mandatory=$false)] | |
[System.IO.Compression.CompressionLevel]$CompressionLevel=[System.IO.Compression.CompressionLevel]::Optimal | |
) | |
[Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | |
[System.IO.Compression.ZipFile]::CreateFromDirectory( $SourceDirectory, $ZipFileName, $compressionLevel, $false ) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment