Achtung: Pfade bitte anpassen!
Task automatisch erstellen:SchTasks /Create /SC WEEKLY /D SAT /TN "Remove IIS logs older than 7 days" /TR "Forfiles.exe -p C:\inetpub\logs\LogFiles\W3SVC1 -m *.log -d -7 -c \"Cmd.exe /C del @path\\"" /ST 11:59
Für alte Server ohne SchTasks:at 12:00 /EVERY:Su Forfiles.exe -p C:\WINDOWS\system32\LogFiles\W3SVC1 -m *.log -d -30 -c \"Cmd.exe /C del @path\"
Wichtig: Task bearbeiten -> Ausführen auf SYSTEM ändern
Falls Exchange 2013 / 2016 Installiert, kann auch folgendes .ps1 Script benutzt werden:
(IIS & Exchange)
Achtung: Pfade bitte ggf. anpassen!
Set-Executionpolicy RemoteSigned
$days=7
$IISLogPath="C:\inetpub\logs\LogFiles\"
$ExchangeLoggingPath="C:\Program Files\Microsoft\Exchange Server\V15\Logging\"
$ETLLoggingPath="C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\ETLTraces\"
$ETLLoggingPath2="C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\Logs"
Function CleanLogfiles($TargetFolder)
{
if (Test-Path $TargetFolder) {
$Now = Get-Date
$LastWrite = $Now.AddDays(-$days)
$Files = Get-ChildItem $TargetFolder -Include *.log,*.blg, *.etl, *.txt -Recurse | Where {$_.LastWriteTime -le "$LastWrite"}
foreach ($File in $Files)
{Write-Host "Deleting file $File" -ForegroundColor "white"; Remove-Item $File -ErrorAction SilentlyContinue | out-null}
}
Else {
Write-Host "The folder $TargetFolder doesn't exist! Check the folder path!" -ForegroundColor "white"
}
}
CleanLogfiles($IISLogPath)
CleanLogfiles($ExchangeLoggingPath)
CleanLogfiles($ETLLoggingPath)
CleanLogfiles($ETLLoggingPath2)
Aufgabenplanung:
Programm:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
Argument:
-command "C:\Scripts\Pfad_zum_Skript.ps1"
SBS SQL Datenbanken verkleinern: Achtung: Pfade bitte anpassen! Das Script muss zwei mal ausgeführt werden, damit die DBs effektiv kleiner werden! cd C:\Backup\ @ECHO OFF SETLOCAL rem Zeitstempel erzeugen for /f "tokens=1-4 delims=. " %%i in ("%date%") do ( set day=%%i set month=%%j set year=%%k ) for /f "tokens=1-4 delims=.:, " %%i in ("%time%") do ( set hour=%%i set minute=%%j set second=%%k set hundredth=%%l ) REM Build a list of databases to backup SET DBList=SQLDBList.txt SqlCmd -E -S \\.\pipe\mssql$microsoft##ssee\sql\query -h-1 -W -Q "SET NoCount ON; SELECT Name FROM master.dbo.sysDatabases WHERE [Name] NOT LIKE 'master' AND [Name] NOT LIKE 'model' AND [Name] NOT LIKE 'msdb' AND [Name] NOT LIKE 'tempdb' AND [Name] NOT LIKE 'SUSDB' AND [Name] NOT LIKE 'WSS_SEARCH%%'" > "%DBList%" REM Backup each database, prepending the date to the filename FOR /F %%I IN (%DBList%) DO ( ECHO Backing up database: %%I SqlCmd -E -S \\.\pipe\mssql$microsoft##ssee\sql\query -Q "BACKUP LOG [%%I] TO DISK = N'
C:\Backup
\SP_Config%%I' WITH NOFORMAT, NOINIT, NAME = N'Sicherung', SKIP, NOREWIND, NOUNLOAD, STATS = 10" ECHO. ) REM Shrink each database, prepending the date to the filename FOR /F %%I IN (%DBList%) DO ( ECHO Shrinking up database: %%I SqlCmd -E -S \\.\pipe\mssql$microsoft##ssee\sql\query -Q "USE [%%I]; DBCC SHRINKFILE (N'%%I_log' , 0, TRUNCATEONLY)" ECHO. ) REM Clean up the temp file IF EXIST “%DBList%” DEL /F /Q “%DBList%” ENDLOCAL
Keine Kommentare:
Kommentar veröffentlichen