diff --git a/Installers/AppPoolRestart.ps1 b/Installers/AppPoolRestart.ps1 new file mode 100644 index 00000000..c477112e --- /dev/null +++ b/Installers/AppPoolRestart.ps1 @@ -0,0 +1,220 @@ + <# +.DESCRIPTION + Stop di una appPoll, cancellazione dir temp ASP.NET, start pool o backup della dir della webapp + ATTENZIONE. Se abilito il backup della app non avvia il pool dopo averlo stoppato + +.PARAMETER + .EXAMPLE IN BAT FILE + +PowerShell.exe .\AppPoolRestart.ps1 ^ + -appPoolName 'Pool GMW Test' ^ + -AppPath 'GMW_Test' ^ + -FramPath '\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\' ^ + -Install $False ^ + -FileLog 'AppPoolRestart_GMW_Test' ^ + -wwwRoot 'C:\inetpub\wwwroot\*.*' ^ + -BackupPath 'D:\Progetti\GMW\Backup_WWWROOT\ +#> + +PARAM ( + [string]$appPoolName = "Pool GMW Test" # App Pool da riavviare + ,[string]$AppPath = "GMW_Test" # Path temporaneo da cancellare + ,[string]$FramPath = "\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\" # dir a cui aggiungo AppPath e poi viene cancellata + + ,[bool]$Install = $True # se $True fa backup dell'app e lascia il pool spento altrimenti riavvia il pool + ,[string]$wwwRoot = "C:\inetpub\wwwroot\*.*" # dir copiata x backup + ,[string]$BackupPath = "D:\Progetti\GMW\Backup_WWWROOT\" # dir a cui viene aggiunta la data e usata x copia backup + + ,[string]$FileLog = "App_PoolRestart" +) + +# Remove-Variable * -ErrorAction SilentlyContinue # pulisco variabili x ISE +CLS + +import-module WebAdministration + +# $appPoolName = 'Pool GMW' +# $AppPath = 'GMW' # dir ASP.NET temporanea da cancellare +# $FramPath = "\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\$AppPath" + +$FramPathDel = $FramPath + $AppPath # es. "\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\GMW_Test" +$TempAspPath = $env:SystemRoot + $FramPathDel # path completo dir ASP.NET temporanea da cancellare +$Date = (Get-Date -format "yyyy-MM-dd HH:mm") +$BackupPath = $BackupPath + (Get-Date -format "yyyy-MM-dd_HH_mm") + '\' # aggiungo data al backup path + +# PARAMETRI PER BACKUP INSTALL APP +# $Install = $False # se $True fa backup dell'app e lascia il pool spento altrimenti riavvia il pool +# $wwwRoot = "C:\inetpub\wwwroot\GMW_Test\*.*" +# $BackupPath = "D:\Progetti\GMW\Backup_WWWROOT\GMW_Test_$Date\" +# $FileLog = "App_PoolRestart" + +# ---------------------------- +# parametri per log errori +# ---------------------------- +# path dello script ps1 mi serve a causa di problemi con lo schedulatore +if ( $MyInvocation.MyCommand.Path -ne $null ) { + $scriptPath = split-path -parent $MyInvocation.MyCommand.Path + } +else { + CD + $scriptPath = "." +} + +$ErrlogFile = "$scriptPath\$FileLog-ErrorLog.txt" # "$scriptPath\ErrLog_Log.txt" # se non lo voglio mettere = $null quindi posso usare una variabile +$LogFile = "$scriptPath\$FileLog-Log.txt" + +$ErrorActionPreference = "Stop" # comportamento x errori minori + +# attivo il Transcript NO per powershell 1.0 +# Start-Transcript -path $LogFile | Out-Null + +">>> Start : $Date" >> $LogFile + +TRY +{ + + $PoolStateIni = (Get-WebAppPoolState $appPoolName).Value # salvo stato pool iniziale + + # STOP APP POOL + if((Get-WebAppPoolState $appPoolName).Value -ne 'Stopped') + { + " Stop Pool : $appPoolName" >> $LogFile + Stop-WebAppPool -Name $appPoolName + } + + # attendo fino a che è Stopped + $try = 5 + $step = 0 + While ( $try -gt $step ) + { + $step++ + + if( (Get-WebAppPoolState $appPoolName).Value -ne 'Stopped') + { + $appPoolName + " " + (Get-WebAppPoolState $appPoolName).Value + Start-Sleep -s 5 + } + else + { + (Get-WebAppPoolState $appPoolName).Value + $step = $try # esco + } + + } #end while + + # ======================================= + # DELETE TEMP E BACKUP o START APP POOL + # ======================================= + if((Get-WebAppPoolState $appPoolName).Value -eq 'Stopped') + { + + # cancello directory Temp ASP.NET + " Delete Dir -> $TempAspPath" >> $LogFile + Remove-Item $TempAspPath -Force -Recurse -ErrorAction SilentlyContinue # se anche non c'è la dir non do errore + + if ( $Install -eq $True ) + { + # COPIA DELLA WebbApp - uso XCOPY così copio anche i permessi + XCOPY $wwwRoot $BackupPath /s /e /h /x /v + Compact /C /S "$BackupPath*.*" # comprimo cartella + + # EXPLORER.exe $BackupPath + } + else # solo restart + { + # riavvio Pool solo se era start all'inizio + if ($PoolStateIni -eq 'Started') { + " Start Pool : $appPoolName" >> $LogFile; + Start-WebAppPool -Name $appPoolName + } + } + } + +} # end TRY + +# ==== GESTIONE ERRORI ===== +CATCH [Exception] +{ + # imposto invio mail di errore + $pMailError = $True + + # salvo errore + "CATCH Error at $Date" > $ErrlogFile + + $error[0] + Write-Output $Error[0] >> $ErrlogFile + + $err = $_.Exception + while ( $err.InnerException ) + { + $err = $err.InnerException + Write-Output $err.Message # anche a video + Write-Output $err.Message >> $ErrlogFile + } +} +# ==== STEP FINALE - sempre eseguito ===== +FINALLY +{ + # SE APP POOL STOPPED LO AVVIO + if((Get-WebAppPoolState $appPoolName).Value -eq 'Stopped' -and $PoolStateIni -eq 'Started' -and $Install -ne $True ) + { + " Start Pool FINALLY : $appPoolName" >> $LogFile + Start-WebAppPool -Name $appPoolName + } + + # "End execute at : $Date" > $ErrlogFile + # ================================ + # INVIO MAIL ( error And success ) + # ================================ +<# if ( $SendMail -and $pMailError ) # ( send con errore ) + { EmailNotification $aListMailError } + + ElseIf ( $SendMail -and $SendMailSuccess ) # ( send if success ) + { EmailNotification $aListMailSuccess } +#> + # Stop capturing output + # Stop-Transcript +} + +<# Comprime ma non tiene le permission + +Add-Type -AssemblyName System.IO.Compression.FileSystem + +$Date = (Get-Date -format "yyyy-MM-dd_HHmm") +$sourcePath = 'C:\inetpub\wwwroot\WebGIM'; +$destPath="C:\Steamware\Test2_$Date.zip"; + +$includeBaseDirectory = $true # nello zip anche cartella base +$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal; + +# zip intera cartella!!! +[System.IO.Compression.ZipFile]::CreateFromDirectory($sourcePath,$destPath, $compressionLevel, $includeBaseDirectory); +#> + +<# + +# errore dice che il file esiste già, forse zip solo della cartella usare CreateEntry? + +Add-Type -AssemblyName System.IO.Compression.FileSystem + +$currentDate = Get-Date; +$currentDate | Get-Member -Membertype Method Add; +$daysBefore = -1; +$archiveTillDate = $currentDate.AddDays($daysBefore); + +$compressionLevel= [System.IO.Compression.CompressionLevel]::Optimal + +foreach( $item in ( Get-ChildItem $sourcePath | Where-Object { $_.CreationTime -le $archiveTillDate }) ) +{ + [System.IO.Compression.ZipFile]::CreateFromDirectory( $sourcePath, $destPath, $compressionLevel, $true); + +} + +#altro +Get-ChildItem "C:\inetpub\wwwroot\WebGIM\*.*" -Recurse | foreach { + $File = $_.fullName + [System.IO.Compression.ZipFile]::CreateFromDirectory($File, "C:\Temp\Folder.zip") + } + +#> + diff --git a/Installers/BackupMP.bat b/Installers/BackupMP.bat new file mode 100644 index 00000000..73a74416 --- /dev/null +++ b/Installers/BackupMP.bat @@ -0,0 +1,40 @@ + +@ECHO OFF + +@REM *** FA BACKUP DELLE APP IN C:\Steamware\IIS_BackUp\ sia con la data odierna che in previous x WinMerge + +@REM SET da solo x vedere le variabili di ambiente +@SETLOCAL + +REM Estraggo dalla Variabile %DATE% i valori di Giorno-Mese-Anno +@SET DAY=%DATE:~4,2% +@SET MONTH=%DATE:~7,2% +@SET YEAR=%DATE:~10,4% + +@REM diversa impostazione Local +@SET DAY=%DATE:~0,2% +@SET MONTH=%DATE:~3,2% +@SET YEAR=%DATE:~6,4% + +@REM Estraggo dalla Variabile %TIME% i valori di Ora-Minuti-Secondi +@SET HOUR=%TIME:~0,2% +@SET MINUTE=%TIME:~3,2% + +@REM sistemo ora quando solo un carattere +@if "%TIME:~0,1%"==" " (set HOUR=0%time:~1,1%) + +@REM IMPOSTO cartella vecchi file +SET BKPDIRMASTER=C:\Steamware\IIS_BackUp\ + +SET BKPFILE=%BKPDIRMASTER%%YEAR%-%MONTH%-%DAY%_%HOUR%_%MINUTE% + +%BKPFILE% +PAUSE + +@ECHO Copio le app sia in \Previous che in cartella con data odierna + +RmDir /S C:\Steamware\IIS_BackUp\Previous\ +xcopy C:\inetpub\wwwroot\MP\*.* %BKPFILE%\*.* /S /E /H /V /K /O /X +xcopy C:\inetpub\wwwroot\MP\*.* %BKPDIRMASTER%\Previous\*.* /S /E /H /V /K /O /X + +PAUSE \ No newline at end of file diff --git a/Installers/MP-ADM-Deploy.bat b/Installers/MP-ADM-Deploy.bat new file mode 100644 index 00000000..909c9539 --- /dev/null +++ b/Installers/MP-ADM-Deploy.bat @@ -0,0 +1,19 @@ + + +SET ThisScriptsDirectory=%~dp0 +SET SetParametersXml=%ThisScriptsDirectory%ParametersXml\MP-ADM.SetParameters.xml +SET PackagePath=%ThisScriptsDirectory%MP\ADM\Jetco\ADM.zip + + + +PowerShell.exe %ThisScriptsDirectory%\AppPoolRestart.ps1 ^ + -appPoolName 'MP-ADM' ^ + -AppPath 'GMW' ^ + -FramPath '\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\' ^ + -Install $False ^ + -FileLog 'AppPoolRestart_ADM' + + +"C:\Program Files\IIS\Microsoft Web Deploy V3\MSDeploy.exe" -source:package="%PackagePath%" -dest:auto,authtype="Basic",includeAcls="False" -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:"%SetParametersXml%" -allowUntrusted + +pause \ No newline at end of file diff --git a/Installers/MP-IO-Deploy.bat b/Installers/MP-IO-Deploy.bat new file mode 100644 index 00000000..ac2292b9 --- /dev/null +++ b/Installers/MP-IO-Deploy.bat @@ -0,0 +1,9 @@ + + +SET ThisScriptsDirectory=%~dp0 +SET SetParametersXml=%ThisScriptsDirectory%ParametersXml\MP-IO.SetParameters.xml +SET PackagePath=%ThisScriptsDirectory%MP\IO\Jetco\IO.zip + +"C:\Program Files\IIS\Microsoft Web Deploy V3\MSDeploy.exe" -source:package="%PackagePath%" -dest:auto,authtype="Basic",includeAcls="False" -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:"%SetParametersXml%" -allowUntrusted + +pause \ No newline at end of file