Riorganizzato conf.ps1
This commit is contained in:
parent
3692d71086
commit
7faa1e8c82
52
script/check-prerequisites.ps1
Normal file
52
script/check-prerequisites.ps1
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# check-prerequisites.ps1
|
||||||
|
# Script per verificare i prerequisiti degli script PowerShell
|
||||||
|
|
||||||
|
function Write-Status {
|
||||||
|
param(
|
||||||
|
[string]$check,
|
||||||
|
[bool]$passed,
|
||||||
|
[string]$details
|
||||||
|
)
|
||||||
|
$status = if ($passed) { "[OK]" } else { "[ERRORE]" }
|
||||||
|
Write-Host "`n$check : $status"
|
||||||
|
if ($details) {
|
||||||
|
Write-Host $details
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Verifica versione PowerShell
|
||||||
|
$psVersion = $PSVersionTable.PSVersion
|
||||||
|
$psVersionOk = $psVersion.Major -ge 5 -and $psVersion.Minor -ge 1
|
||||||
|
Write-Status -check "Versione PowerShell" -passed $psVersionOk -details "Versione installata: $($psVersion.ToString())`nVersione minima richiesta: 5.1"
|
||||||
|
|
||||||
|
# Verifica System.Data assembly
|
||||||
|
try {
|
||||||
|
Add-Type -AssemblyName System.Data
|
||||||
|
$adoNetOk = $true
|
||||||
|
Write-Status -check "ADO.NET System.Data" -passed $true -details "Assembly System.Data caricato correttamente"
|
||||||
|
} catch {
|
||||||
|
$adoNetOk = $false
|
||||||
|
Write-Status -check "ADO.NET System.Data" -passed $false -details "Errore nel caricamento di System.Data"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Verifica SqlCommand
|
||||||
|
try {
|
||||||
|
$connection = New-Object System.Data.SqlClient.SqlConnection
|
||||||
|
$command = New-Object System.Data.SqlClient.SqlCommand("", $connection)
|
||||||
|
$sqlCommandOk = $true
|
||||||
|
Write-Status -check "SQL Command" -passed $true -details "Creazione SqlCommand riuscita"
|
||||||
|
} catch {
|
||||||
|
$sqlCommandOk = $false
|
||||||
|
Write-Status -check "SQL Command" -passed $false -details "Errore nella creazione di SqlCommand: $($_.Exception.Message)"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Riepilogo finale
|
||||||
|
$allOk = $psVersionOk -and $adoNetOk -and $sqlCommandOk
|
||||||
|
Write-Host "`n----------------------------------------"
|
||||||
|
$exitMessage = if ($allOk) { "Tutti i prerequisiti sono soddisfatti" } else { "ATTENZIONE: Alcuni prerequisiti non sono soddisfatti" }
|
||||||
|
$exitColor = if ($allOk) { "Green" } else { "Red" }
|
||||||
|
Write-Host $exitMessage -ForegroundColor $exitColor
|
||||||
|
Write-Host "----------------------------------------"
|
||||||
|
|
||||||
|
# Restituisci il risultato complessivo
|
||||||
|
exit ([int](-not $allOk))
|
@ -1,48 +1,76 @@
|
|||||||
|
# Database C6StampeCentralizzate collaudo
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')]
|
||||||
|
$DBStampeColl = @{
|
||||||
|
sqlServerName = "bfdskrepsei01c.sysfideuram.sysbancafideuram.it"
|
||||||
|
databaseName = "C6StampeCentralizzate"
|
||||||
|
userName = "F701264"
|
||||||
|
securePassword = "contrsei"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Database C6StampeCentralizzate produzione
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')]
|
||||||
|
$DBStampeProd = @{
|
||||||
|
sqlServerName = "bfdskreport01p.fideuram.bancafideuram.it"
|
||||||
|
databaseName = "C6StampeCentralizzate"
|
||||||
|
userName = "F701264"
|
||||||
|
securePassword = "contrsei"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Database SEIReport Lettera benvenuto Produzione
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')]
|
||||||
|
$DBBenvProd = @{
|
||||||
|
sqlServerName = "bfdskreport02p.fideuram.bancafideuram.it"
|
||||||
|
databaseName = "SEIReport"
|
||||||
|
userName = "SEIReport"
|
||||||
|
securePassword = "SEIReport"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Database C6StampeCentralizzate locale
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')]
|
||||||
|
$DBStampeLoc = @{
|
||||||
|
sqlServerName = "DATABASE_PDC_LOCALE"
|
||||||
|
databaseName = "C6StampeCentralizzate"
|
||||||
|
userName = "F701264"
|
||||||
|
securePassword = "contrsei"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Database C6StampeCentralizzate testbes
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')]
|
||||||
|
$DBStampeTestbes = @{
|
||||||
|
sqlServerName = "testbes.armundia.com"
|
||||||
|
databaseName = "C6StampeCentralizzate"
|
||||||
|
userName = "sa"
|
||||||
|
securePassword = "_p1sap1a"
|
||||||
|
}
|
||||||
|
|
||||||
# Configurazione database
|
# Configurazione database
|
||||||
$config = @{
|
$config = @{
|
||||||
# Credenziali database
|
|
||||||
# DbUser = "sa"
|
|
||||||
# DbPassword = "_p1sap1a"
|
|
||||||
# DbUser = "SEIReport"
|
|
||||||
# DbPassword = "SEIReport"
|
|
||||||
DbUser = "F701264"
|
|
||||||
DbPassword = "contrsei"
|
|
||||||
|
|
||||||
# DbHostOutput
|
|
||||||
DbHostOutput = "DATABASE_PDC_LOCALE"
|
|
||||||
# DbHostOutput = "testbes.armundia.com"
|
|
||||||
|
|
||||||
# DbHostInput
|
|
||||||
# DbHostInput = "bfdskrepsei01c.sysfideuram.sysbancafideuram.it"
|
|
||||||
# DbHostInput = "testbes.armundia.com"
|
|
||||||
# DbHostInput = "DATABASE_PDC_LOCALE"
|
|
||||||
DbHostInput = "bfdskreport01p.fideuram.bancafideuram.it"
|
|
||||||
# DbHostInput = "bfdskreport02p.fideuram.bancafideuram.it"
|
|
||||||
# DbName = "master"
|
|
||||||
ServerName = "CONSUNI"
|
|
||||||
DbName = "C6StampeCentralizzate"
|
|
||||||
# DbName = "SEIReport"
|
|
||||||
|
|
||||||
# Directory di log
|
# Directory di log
|
||||||
WorkDir = Split-Path -Path $PSScriptRoot -Parent
|
WorkDir = Split-Path -Path $PSScriptRoot -Parent
|
||||||
LogDir = Join-Path (Split-Path -Path $PSScriptRoot -Parent) "logs"
|
LogDir = Join-Path (Split-Path -Path $PSScriptRoot -Parent) "logs"
|
||||||
SqlDir = Join-Path (Split-Path -Path $PSScriptRoot -Parent) "sql"
|
SqlDir = Join-Path (Split-Path -Path $PSScriptRoot -Parent) "sql"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$DBI = $DBBenvProd
|
||||||
|
$DBO = $DBStampeLoc
|
||||||
# Esporta le variabili come variabili d'ambiente
|
# Esporta le variabili come variabili d'ambiente
|
||||||
$env:dbUser = $config.DbUser
|
$env:dbHostInput = $DBI.sqlServerName
|
||||||
$env:dbPassword = $config.DbPassword
|
$env:dbNameInput = $DBI.databaseName
|
||||||
$env:dbHostInput = $config.DbHostInput
|
$env:dbUserInput = $DBI.userName
|
||||||
$env:dbHostOutput = $config.DbHostOutput
|
$env:dbPasswordInput = $DBI.securePassword
|
||||||
$env:dbName = $config.DbName
|
|
||||||
|
$env:dbHostOutput = $DBO.sqlServerName
|
||||||
|
$env:dbNameOutput = $DBO.databaseName
|
||||||
|
$env:dbUserOutput = $DBO.userName
|
||||||
|
$env:dbPasswordOutput = $DBO.securePassword
|
||||||
|
|
||||||
$env:logDir = $config.LogDir
|
$env:logDir = $config.LogDir
|
||||||
$env:workDir = $config.WorkDir
|
$env:workDir = $config.WorkDir
|
||||||
$env:sqlDir = $config.SqlDir
|
$env:sqlDir = $config.SqlDir
|
||||||
$env:ServerName = $config.ServerName
|
|
||||||
|
|
||||||
# Funzione per ottenere la connection string
|
# Funzione per ottenere la connection string
|
||||||
function Get-DatabaseConnectionString {
|
function Get-DatabaseConnectionString {
|
||||||
return "Server=$($config.DbHostOutput);Database=$($config.DbName);User Id=$($config.DbUser);Password=$($config.DbPassword);"
|
return "Server=$($DBO.sqlServerName);Database=$($DBO.databaseName);User Id=$($DBO.userName);Password=$($DBO.securePassword);"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Crea directory di log se non esiste
|
# Crea directory di log se non esiste
|
||||||
|
@ -86,7 +86,7 @@ foreach ($fileSql in $filesToExecute) {
|
|||||||
while (-not $success -and $retryCount -lt $maxRetries) {
|
while (-not $success -and $retryCount -lt $maxRetries) {
|
||||||
try {
|
try {
|
||||||
# Execute SQL and capture all output
|
# Execute SQL and capture all output
|
||||||
$output = & sqlcmd -S $env:dbHostOutput -U $env:dbUser -P $env:dbPassword -d $env:dbName -i $fileSql -b 2>&1
|
$output = & sqlcmd -S $env:dbHostOutput -U $env:dbUserOutput -P $env:dbPasswordOutput -d $env:dbNameOutput -i $fileSql -b 2>&1
|
||||||
$esitoComando = $LASTEXITCODE
|
$esitoComando = $LASTEXITCODE
|
||||||
|
|
||||||
# Save output to log file and process it
|
# Save output to log file and process it
|
||||||
|
@ -151,16 +151,16 @@ try {
|
|||||||
THEN t.name + '(' + CAST(c.[precision] AS VARCHAR) + ',' + CAST(c.[scale] AS VARCHAR) + ')'
|
THEN t.name + '(' + CAST(c.[precision] AS VARCHAR) + ',' + CAST(c.[scale] AS VARCHAR) + ')'
|
||||||
ELSE t.name
|
ELSE t.name
|
||||||
END as FullDataType
|
END as FullDataType
|
||||||
FROM [$env:serverName].[$dbName].sys.columns c
|
FROM [$env:dbHostInput].[$dbName].sys.columns c
|
||||||
INNER JOIN [$env:serverName].[$dbName].sys.types t ON c.user_type_id = t.user_type_id
|
INNER JOIN [$env:dbHostInput].[$dbName].sys.types t ON c.user_type_id = t.user_type_id
|
||||||
INNER JOIN [$env:serverName].[$dbName].sys.tables tbl ON c.object_id = tbl.object_id
|
INNER JOIN [$env:dbHostInput].[$dbName].sys.tables tbl ON c.object_id = tbl.object_id
|
||||||
WHERE SCHEMA_NAME(tbl.schema_id) = '$schemaName'
|
WHERE SCHEMA_NAME(tbl.schema_id) = '$schemaName'
|
||||||
AND tbl.name = '$tableName'
|
AND tbl.name = '$tableName'
|
||||||
ORDER BY c.column_id
|
ORDER BY c.column_id
|
||||||
"@
|
"@
|
||||||
|
|
||||||
# Ottieni la struttura delle colonne
|
# Ottieni la struttura delle colonne
|
||||||
$columns = Invoke-Sqlcmd -ServerInstance $env:dbHostInput -Database $env:dbName -Query $columnQuery -Username $env:dbUser -Password $env:dbPassword -TrustServerCertificate
|
$columns = Invoke-Sqlcmd -ServerInstance $env:dbHostInput -Database $env:dbNameInput -Query $columnQuery -Username $env:dbUserInput -Password $env:dbPasswordInput -TrustServerCertificate
|
||||||
|
|
||||||
# Costruisci la CREATE TABLE
|
# Costruisci la CREATE TABLE
|
||||||
$createTableScript = "CREATE TABLE [$dbName].[$schemaName].[$tableName] (`n"
|
$createTableScript = "CREATE TABLE [$dbName].[$schemaName].[$tableName] (`n"
|
||||||
@ -184,7 +184,7 @@ GO
|
|||||||
|
|
||||||
-- Popolamento tabella
|
-- Popolamento tabella
|
||||||
-- INSERT INTO [$dbName].[$schemaName].[$tableName]
|
-- INSERT INTO [$dbName].[$schemaName].[$tableName]
|
||||||
-- SELECT * FROM [$env:serverName].[$dbName].[$schemaName].[$tableName];
|
-- SELECT * FROM [$env:dbHostInput].[$dbName].[$schemaName].[$tableName];
|
||||||
-- GO
|
-- GO
|
||||||
"@
|
"@
|
||||||
|
|
||||||
|
@ -34,11 +34,11 @@ try {
|
|||||||
"@
|
"@
|
||||||
|
|
||||||
# Esegui la query e salva i risultati
|
# Esegui la query e salva i risultati
|
||||||
$connectionString = "Server=$($config.DbHostInput);Database=$($config.DbName);User Id=$($config.DbUser);Password=$($config.DbPassword);TrustServerCertificate=True"
|
$connectionString = "Server=$($env:dbHostInput);Database=$($env:dbNameInput);User Id=$($env:dbUserInput);Password=$($env:dbPasswordInput);TrustServerCertificate=True"
|
||||||
$results = Invoke-Sqlcmd -ConnectionString $connectionString -Query $query
|
$results = Invoke-Sqlcmd -ConnectionString $connectionString -Query $query
|
||||||
|
|
||||||
# Prepara l'output
|
# Prepara l'output
|
||||||
$output = "Elenco oggetti del database $($config.DbName) su $($config.DbHostInput) il $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')`r`n"
|
$output = "Elenco oggetti del database $($env:DbName) su $($env:DbHostInput) il $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')`r`n"
|
||||||
$output += "Tipo;Schema;Nome`r`n"
|
$output += "Tipo;Schema;Nome`r`n"
|
||||||
|
|
||||||
# Formatta e aggiungi ogni oggetto all'output
|
# Formatta e aggiungi ogni oggetto all'output
|
||||||
|
@ -34,13 +34,13 @@ try {
|
|||||||
Import-Module SqlServer
|
Import-Module SqlServer
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Connessione a $env:dbHostInput, database $env:dbName..."
|
Write-Host "Connessione a $env:dbHostInput, database $env:dbNameInput..."
|
||||||
|
|
||||||
# Esegui la query e salva i risultati
|
# Esegui la query e salva i risultati
|
||||||
$result = Invoke-Sqlcmd -ServerInstance $env:dbHostInput `
|
$result = Invoke-Sqlcmd -ServerInstance $env:dbHostInput `
|
||||||
-Database $env:dbName `
|
-Database $env:dbNameInput `
|
||||||
-Username $env:dbUser `
|
-Username $env:dbUserInput `
|
||||||
-Password $env:dbPassword `
|
-Password $env:dbPasswordInput `
|
||||||
-TrustServerCertificate `
|
-TrustServerCertificate `
|
||||||
-Query $Query
|
-Query $Query
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ try {
|
|||||||
"@
|
"@
|
||||||
|
|
||||||
# Esegui la query
|
# Esegui la query
|
||||||
$sqlObjects = Invoke-Sqlcmd -ServerInstance $env:dbHostInput -Database $env:dbName -Query $query -Username $env:dbUser -Password $env:dbPassword -MaxCharLength 1000000 -TrustServerCertificate
|
$sqlObjects = Invoke-Sqlcmd -ServerInstance $env:dbHostInput -Database $env:dbNameInput -Query $query -Username $env:dbUserInput -Password $env:dbPasswordInput -MaxCharLength 1000000 -TrustServerCertificate
|
||||||
|
|
||||||
# Funzione per pulire il nome del file
|
# Funzione per pulire il nome del file
|
||||||
function Clean-FileName {
|
function Clean-FileName {
|
||||||
|
@ -95,10 +95,10 @@ try {
|
|||||||
|
|
||||||
$sqlParams = @{
|
$sqlParams = @{
|
||||||
ServerInstance = $env:dbHostInput
|
ServerInstance = $env:dbHostInput
|
||||||
Database = $env:dbName
|
Database = $env:dbNameInput
|
||||||
Query = $query
|
Query = $query
|
||||||
Username = $env:dbUser
|
Username = $env:dbUserInput
|
||||||
Password = $env:dbPassword
|
Password = $env:dbPasswordInput
|
||||||
MaxCharLength = 1000000
|
MaxCharLength = 1000000
|
||||||
TrustServerCertificate = $true
|
TrustServerCertificate = $true
|
||||||
ConnectionTimeout = 30
|
ConnectionTimeout = 30
|
||||||
|
@ -45,7 +45,7 @@ try {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Connessione a $env:dbHostOutput, database $env:dbName..."
|
Write-Host "Connessione a $env:dbHostOutput, database $env:dbNameOutput..."
|
||||||
|
|
||||||
# Get column names from CSV
|
# Get column names from CSV
|
||||||
$columns = $data[0].PSObject.Properties.Name
|
$columns = $data[0].PSObject.Properties.Name
|
||||||
@ -79,7 +79,7 @@ try {
|
|||||||
$query = "INSERT INTO $TableName ($columnList) VALUES ($valuesList)"
|
$query = "INSERT INTO $TableName ($columnList) VALUES ($valuesList)"
|
||||||
|
|
||||||
# Execute insert for each row
|
# Execute insert for each row
|
||||||
$connectionString = "Server=$env:dbHostOutput;Database=$env:dbName;User Id=$env:dbUser;Password=$env:dbPassword;Encrypt=False"
|
$connectionString = "Server=$env:dbHostOutput;Database=$env:dbNameOutput;User Id=$env:dbUserOutput;Password=$env:dbPasswordOutput;Encrypt=False"
|
||||||
|
|
||||||
Invoke-Sqlcmd -ConnectionString $connectionString `
|
Invoke-Sqlcmd -ConnectionString $connectionString `
|
||||||
-Query $query
|
-Query $query
|
||||||
|
@ -7,7 +7,7 @@ $logFile = Join-Path $env:logDir "${scriptName}.log"
|
|||||||
"Start pulizia stored procedure $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" | Out-File -FilePath $logFile
|
"Start pulizia stored procedure $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" | Out-File -FilePath $logFile
|
||||||
|
|
||||||
# Connessione al database
|
# Connessione al database
|
||||||
$connectionString = "Server=$env:dbHostOutput;Database=$env:dbName;User Id=$env:dbUser;Password=$env:dbPassword;"
|
$connectionString = "Server=$env:dbHostOutput;Database=$env:dbNameOutput;User Id=$env:dbUserOutput;Password=$env:dbPasswordOutput;"
|
||||||
$connection = New-Object System.Data.SqlClient.SqlConnection($connectionString)
|
$connection = New-Object System.Data.SqlClient.SqlConnection($connectionString)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user