View Full Version : Server Storage Management
Albiz849
15-11-2013, 11:33
Buongiorno!
Oggi sto lavorando con una VM con Windows server 2008 R2 avente come ruolo File Services, in particolare File Server e File Server Resource Manager. Ho impostato una cartella, su cui ho il controllo completo, chiamata Test sulla quale vorrei effettuare un test appunto per capire come posso fare quanto segue. :help:
Premetto che ciò che voglio fare va schedulato in modo che venga applicato ogni giorno alle 13.
Voglio eliminare tutti i file Temporanei quali Thumbs.db o i file di "Backup" di office, per chiarirci quelli che hanno il $ e che vengono creati quando il programma crasha, o simili.
Per lo specifico file Thumbs.db ho già introdotto una regola ad obiectum, ma per gli altri file no...
Inoltre esiste un modo per eliminare le cartelle vuote in automatico?
Non sono molto pratico in merito; avreste qualche suggerimento? :help:
Grazie
A
Tasslehoff
15-11-2013, 14:34
Io lo farei con un semplice script bash installando cygwin sul server.
Ti basta usare il comando find ed rm.
Per i file puoi usare
find <PATH> -type f -name '\$*' -o -name 'Thumbs.db' | xargs rm -f
Per le directory puoi lanciare
find <PATH> -type d | xargs rmdir --ignore-fail-on-non-empty
Albiz849
15-11-2013, 15:01
Io lo farei con un semplice script bash installando cygwin sul server.
Ti basta usare il comando find ed rm.
Per i file puoi usare
find <PATH> -type f -name '\$*' -o -name 'Thumbs.db' | xargs rm -f
Per le directory puoi lanciare
find <PATH> -type d | xargs rmdir --ignore-fail-on-non-empty
Per i file temporanei forse ho già una soluzione, ormai la verifico lunedì, che per ogni estensione di file temporaneo crea una regola x l'eliminazione (ok 5 regole per 5 estensioni diverse non è il massimo ma dovrebbe funzionare).
Quanto alla directory... ehm... di script non ne so niente :-( hai per caso una guida? TNX :-)
malatodihardware
15-11-2013, 21:07
Visto che è su Windows perchè installare cygwin e non usare PowerShell?
http://technet.microsoft.com/en-us/library/hh849852.aspx
Tasslehoff
15-11-2013, 22:45
Visto che è su Windows perchè installare cygwin e non usare PowerShell?
http://technet.microsoft.com/en-us/library/hh849852.aspxIo trovo molto più vantaggioso usare la bash anche solo per una pura questione di riusabilità degli script.
Non discuto della potenza di Powershell, però il fatto di essere limitato a Windows imho è sufficiente per scartarlo a priori.
malatodihardware
16-11-2013, 07:35
Dipende cosa gestisci.. Se sono solo server Windows non ha senso usare altro, visto che l'editor con debugger è già compreso ed è un software nativo
Inviato dal mio Nexus 5 con Tapatalk
Albiz849
18-11-2013, 08:01
Buongiorno!
Vi ringrazio per le risposte, vi informo inoltre che sto lavorando solo su server Windows, o per lo meno l'unico file service è su vm Windows.
Spero di poter consultare a breve il link fornito ma oggi il sito Microsoft TechNet sembra non funzionare, spero che la cosa si risolva in breve tempo.
Vorrei, se possibile, sapere se esiste un metodo per generare un report sui file duplicati; io ho già provato con il "tool" presente nello Storage Reports Management ma identifica solo file con lo stesso nome, a me servirebbe un controllo bit a bit. Preciso che attualmente, se un file si chiama a.ext e ne rinomino una copia in A.ext non viene visto come duplicato; a me farebbe piacere poter rinominare la copia di a.ext in b.ext e farli identificare come doppioni, duplicati insomma....
Grazie
A
Albiz849
18-11-2013, 14:25
Io lo farei con un semplice script bash installando cygwin sul server.
Ti basta usare il comando find ed rm.
Per i file puoi usare
find <PATH> -type f -name '\$*' -o -name 'Thumbs.db' | xargs rm -f
Per le directory puoi lanciare
find <PATH> -type d | xargs rmdir --ignore-fail-on-non-empty
$Dir="C:\Test"
foreach( $In in(Get-ChildItem $Dir -Recurse){
if(!(Get-ChildItem -Path $In.FullName)){
echo $In.FullName;
Remove-Item $In.FullName
}
}
Get-ExecutionPolicy=Restricted
Ho salvato lo script in ps1... ma come faccio a schedularlo?
grazie
A
malatodihardware
18-11-2013, 18:09
Con il task scheduler metti un'action con Program/Script "Powershell" e argument il percorso del file ps1
Albiz849
19-11-2013, 09:37
Grazie!!!
A
Albiz849
19-11-2013, 11:25
:doh:CVD
ecco il classico errore di distrazione...
Alcune cartelle sono organizzate con dei numeri come prefisso es 00 - Organizzazione... queste cartelle, sebbene possano essere vuote NON DEVONO ESSERE ELIMINATE. Cosa che puntualmente non avviene... pensavo a un ciclo if(Folder start with(lista)){skip}
Come va scritto x powershell ?
Grazie
A
$Dir="C:\Test"
$Et1="0"
$Et2="9"
foreach( $In in(Get-ChildItem $Dir -Recurse)){ #per ogni cartella in $Dir
if(!(Get-ChildItem -Path $In.FullName)){ #se non hai figli
$Sav=Split-Path( $In ) -leaf; #prendi il nome della cartella
if(!($Sav.StartsWith($Et1)) -and (!($Sav.StartsWith($Et2)))){ #se non fa parte delle eccezioni
echo $In.FullName; #stampa
#Remove-Item $In.FullName
}
}
}
Albiz849
20-11-2013, 12:08
Per la serie... sono un rompi*****...
Sto tentando di creare un report per i file duplicati, dato che non ho intenzione di affidarmi a software o regole di default...
Quindi ho preso uno script per i file duplicati e un generatore di file html e sto tentando di metterli assieme...
function Get-Double {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,
Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[System.String]
[Alias('PSPath')]
$Path
)
if ((Test-Path -Path $Path) -eq $false) {
throw New-Object System.IO.FileNotFoundException($Path)
}
try {
$item = Get-Item -Path $Path -Force -ErrorAction Stop
}
catch {
throw
}
if ($item -isnot [System.IO.FileInfo]) {
throw New-Object System.ArgumentException('Specified path must refer to a File object.','Path')
}
try {
$bytes = [System.IO.File]::ReadAllBytes($item.FullName)
} catch {
throw
}
$md5Hash = [System.Security.Cryptography.MD5]::Create()
$hashBytes = $md5Hash.ComputeHash($bytes)
$sb = New-Object System.Text.StringBuilder
foreach ($byte in $hashBytes) {
$sb.Append($byte.ToString("x2")) | Out-Null
}
Write-Output $sb.ToString()
}
$files = @{}
$folder = 'C:\Test\' # Il percorso su cui lavorare
Get-ChildItem -Path $folder -Force -Recurse |
Where-Object { $_ -is [System.IO.FileInfo] } |
ForEach-Object {
try {
$hash = $_ | Get-Double
} catch {
Write-Error -ErrorRecord $_
return
}
if ($files.ContainsKey($hash) -eq $false) {
$files[$hash] = New-Object 'System.Collections.Generic.List[System.String]'
} else {
# I'm just identifying duplicates by adding all their names to a list.
# Keep in mind that if two files have identical hashes, they could have
# different contents; it's possible for two different inputs to produce the same
# hash code.
}
$files[$hash].Add($_.FullName)
}
$data=@()
foreach ($entry in $files.GetEnumerator()) {
if ($entry.Value.Count -gt 1) {
$data=$data+$entry.Value
}
}
#$data= $data | sort{Split-Path( $data ) -leaf} possibilità di ordinare per nome(Verificare)
$drives = foreach ($path in $data) {
$prophash = @{
Nome= split-path $path -leaf
Percorso = $path
}
#create a new object from the property hash
New-Object PSObject -Property $prophash
}
#embed the style in the html header
$head = @'
<Title>Double Report</Title>
<style>
body
{
background-color:#FFFFFF;
font-family:Verdana;
font-size:12pt;
}
td, th
{
border:1px solid blue;
border-collapse:collapse;
}
th
{
color:white;
background-color:green;
}
table, tr, td, th { padding: 5px; margin: 0px }
table { margin-left:50px; }
</style>
'@
#create an xml document from the HTML fragment
[xml]$html = $drives | ConvertTo-Html -fragment
#check each row, skipping the TH header row
for ($i=1;$i -le $html.table.tr.count-1;$i++) {
$class = $html.CreateAttribute("class")
}
#create the final report from the innerxml which should be html code
$body = @"
<H1>Double Report for $Folder</H1>
$($html.innerxml)
"@
#put it all together
ConvertTo-HTML -head $head -PostContent "<br><i>$(Get-date)</i>" -body $body |
Out-File "C:\Test\Double.html" -Encoding ascii
Invoke-Item "C:\Test\Double.html"
viene generato un file html, se ad esempio ho 3 serie di doppioni, alla fine del processo ho sempre e solo 1 file html che mi riporterà i valori di tutte le serie; Magari si può tentare di migliorarlo un po'...
Grazie di tutto!!!!
Adesso provo a farlo girare sul server... :-)
A
Albiz849
22-11-2013, 14:39
Ciao!
Vorrei modificare gli attributi di alcuni file.
se il file è nascosto va tolto il flag e renderlo dunque visibile
Se vi viene in mente qualcosa...
Grazie!!
A
Albiz849
26-11-2013, 13:19
$Move=@()
$Att=@{}
$Today = Get-Date -Format "dd-MM"
$Folder= "C:\Estinto\$Today"
if(!(Test-Path $Folder)){
New-Item -Path $Folder -ItemType directory
}
$Ent=Get-ChildItem "C:\Test" -Recurse -Force -include *.$YY$, *.tmp, *.temp, *.DS_Store, *.part, ~$*, Thumbs.db
foreach($i in $Ent){
if($i.mode -match "h"){
$Att[$i]=$i.Attributes
$Att[$i]=$Att[$i] | where{$_ -ne "Hide"} #questo non va
$i.Attributes = $Att[$i]
}
$Move=$Move+$i.fullname
Move-Item $i.fullname -Destination $Folder
}
$Move= $Move | sort{Split-Path( $_ ) -leaf}
$drives = foreach ($path in $Move) {
$prophash = @{
Nome= split-path $path -leaf
Percorso = $path
}
#create a new object from the property hash
New-Object PSObject -Property $prophash
}
#embed the style in the html header
$head = @'
<Title>Deleting Temp Report</Title>
<style>
body
{
background-color:#FFFFFF;
font-family:Verdana;
font-size:12pt;
}
td, th
{
border:1px solid blue;
border-collapse:collapse;
}
th
{
color:white;
background-color:green;
}
table, tr, td, th { padding: 5px; margin: 0px }
table { margin-left:50px; }
</style>
'@
#create an xml document from the HTML fragment
[xml]$html = $drives | ConvertTo-Html -fragment
#check each row, skipping the TH header row
for ($i=1;$i -le $html.table.tr.count-1;$i++) {
$class = $html.CreateAttribute("class")
}
#create the final report from the innerxml which should be html code
$body = @"
<H1>Deleting Temp Report for $Folder</H1>
$($html.innerxml)
"@
#put it all together
$Name = "Deleting Temp " + $Today
ConvertTo-HTML -head $head -PostContent "<br><i>$(Get-date)</i>" -body $body |
Out-File "C:\Log\$Name.html" -Encoding ascii
Invoke-Item "C:\Log\$Name.html"
la pecca è che toglie tutti gli attributi... vorrei che togliesse solo l'attributo nascosto...
Grazie!!
A
vBulletin® v3.6.4, Copyright ©2000-2026, Jelsoft Enterprises Ltd.