Archivi tag: operazione pianificata

Riavvio pianificato rapido

scheduleVorreste programmare un riavvio rapidamente?

Usate un batch di Windows!

Ecco come fare:

per programmare un riavvio una tantum del computer aprite il blocco note ed incollate il contenuto seguente in un file schedula.bat.

Lanciate il file, impostate l’ora ed il gioco è fatto!

Potrete poi rilanciare il batch ogni volta che avrete bisogno di un riavvio programmato.

@echo off
SETLOCAL
SET /P RestartHour=Inserire ora del riavvio (es.04 per le 4 di mattina) includendo lo zero se necessario 


SET /a TEST=%RESTARTHOUR%

IF "%TEST%"=="-1" (
schtasks /query /tn ScheduledRestart >NUL 2>&1 && schtasks /Delete /tn ScheduledRestart /F || echo "Nessuna schedulazione presente" 
exit /b
)

IF %TEST% GEQ 24 (
    echo ORARIO NON AMMESSO!
    exit /b
)
SET NOWTIME=%TIME:~0,2%%TIME:~3,2%
SET SCHTIME=%RestartHour%00
SET today=%date%

CALL:DateToJDN %today% todayNo
SET /a tomorrowNo=todayNo+1

CALL:JDNToDate %tomorrowNo% tomorrow

IF %NOWTIME% GEQ %SCHTIME% (
    echo Schedulato riavvio domani alle %SCHTIME:~0,2%:00
    set SCHDAY=%TOMORROW:~0,2%/%TOMORROW:~3,2%/%TOMORROW:~6,4%
) ELSE (
    echo Schedulato riavvio oggi alle %SCHTIME:~0,2%:00
    set SCHDAY=%DATE:~0,2%/%DATE:~3,2%/%DATE:~6,4%
)    
schtasks /create /f /tn ScheduledRestart /tr "shutdown /r /t 120 /c """Reboot from RMM""" /f" /sc minute /mo 1 /st %RestartHour%:00:00 /et %RestartHour%:02:00 /z /SD %SCHDAY%  /RL HIGHEST /RU SYSTEM >NUL
echo.
echo.
echo SCHEDULAZIONI:
schtasks | findstr ScheduledRestart
echo.
echo.
echo RICORDA:
echo Per cancellare questa schedulazione lanciare lo script inserendo come orario -1 
echo Per vedere le schedulazioni lanciare il comando: schtasks | findstr ScheduledRestart

GOTO:EOF

:::::Converte la data in numero

:DateToJDN dd.mm.yyyy jdn=
setlocal
set date=%1
set /A yy=%date:~-4%, mm=1%date:~-7,2% %% 100, dd=1%date:~-10,2% %% 100
set /A a=mm-14, jdn=(1461*(yy+4800+a/12))/4+(367*(mm-2-12*(a/12)))/12-(3*((yy+4900+a/12)/100))/4+dd-32075
endlocal & set %2=%jdn%
exit /B

:::::Converte il numero in data

:JDNToDate jdn dd.mm.yyyy=
setlocal
set /A l=%1+68569,n=(4*l)/146097,l=l-(146097*n+3)/4,i=(4000*(l+1))/1461001,l=l-(1461*i)/4+31,j=(80*l)/2447,dd=l-(2447*j)/80,l=j/11,mm=j+2-(12*l),yy=100*(n-49)+i+l
if %dd% lss 10 set dd=0%dd%
if %mm% lss 10 set mm=0%mm%
endlocal & set %2=%dd%.%mm%.%yy%
exit /B

endlocal

.

.

.

.

.

.

.

.

.

.

.

Notifiche Windows Server Backup tramite e-mail pianificate

Windows backup notification Usate Windows Server Backup e vorreste ricevere le notifiche dell’esito del backup?

Un’operazione pianificata vi aiuterà!

Ecco come fare:

Create, sul server che effettua il backup, due operazioni pianificate (una per il backup riuscito l’altra per il backup con errori) importando i seguenti files XML (personalizzando le parti evidenziate):

File BackupKO.xml

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2012-11-22T10:58:40.4469273</Date>
    <Author>NOMEDOMINIO\utente</Author>
  </RegistrationInfo>
  <Triggers>
    <EventTrigger>
      <Enabled>true</Enabled>
      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Microsoft-Windows-Backup"&gt;&lt;Select Path="Microsoft-Windows-Backup"&gt;*[System[(EventID=5 or EventID=8 or EventID=17 or EventID=18 or EventID=19 or EventID=20 or EventID=21 or EventID=22 or EventID=49 or EventID=50 or EventID=52 or EventID=100 or EventID=517 or EventID=518 or EventID=521 or EventID=527 or EventID=528 or EventID=544 or EventID=545 or EventID=546 or EventID=561 or EventID=564 or EventID=612)]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
    </EventTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>NOMEDOMINIO\utente</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT4H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <SendEmail>
      <Server>127.0.0.1</Server>
      <Subject>Errore backup server</Subject>
      <To>info@acme.it</To>
      <From>info@acme.it</From>
      <Body>Verificare il backup da Windows server backup.</Body>
      <HeaderFields />
      <Attachments />
    </SendEmail>
  </Actions>
</Task>

E file BackupOK.xml

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2012-11-22T10:58:40.4469273</Date>
    <Author>NOMEDOMINIO\utente</Author>
  </RegistrationInfo>
  <Triggers>
    <EventTrigger>
      <Enabled>true</Enabled>
      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Microsoft-Windows-Backup"&gt;&lt;Select Path="Microsoft-Windows-Backup"&gt;*[System[(EventID=4)]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
    </EventTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>NOMEDOMINIO\utente</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT4H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <SendEmail>
      <Server>127.0.0.1</Server>
      <Subject>BACKUP OK </Subject>
      <To>info@acme.it</To>
      <From>info@acme.it</From>
      <Body>Backup terminato correttamente.</Body>
      <HeaderFields />
      <Attachments />
    </SendEmail>
  </Actions>
</Task>

Nei server con sistema operativo Windows 2012 R2 il comando di invio e-mail è deprecato per cui ricorriamo a Powershell. Lanceremo quindi al posto dell’attività “Invio messaggio di posta elettronica (deprecato)” l’attività “Avvio programma” con i seguenti parametri:

Programma o script:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Parametro:
-command ” & {Send-MailMessage -SMTPServer 127.0.0.1 -To ‘info@acme.it’ -From ‘info@acme.it’ -Subject ‘Errore backup server’ -Body ‘Verificare il backup da Windows server backup.’}”

O più semplicemente usare i seguenti file:

File BackupKO-2012R2.xml

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2012-11-22T10:58:40.4469273</Date>
    <Author>NOMEDOMINIO\utente</Author>
  </RegistrationInfo>
  <Triggers>
    <EventTrigger>
      <Enabled>true</Enabled>
      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Microsoft-Windows-Backup"&gt;&lt;Select Path="Microsoft-Windows-Backup"&gt;*[System[(EventID=5 or EventID=8 or EventID=17 or EventID=18 or EventID=19 or EventID=20 or EventID=21 or EventID=22 or EventID=49 or EventID=50 or EventID=52 or EventID=100 or EventID=517 or EventID=518 or EventID=521 or EventID=527 or EventID=528 or EventID=544 or EventID=545 or EventID=546 or EventID=561 or EventID=564 or EventID=612)]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
    </EventTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>NOMEDOMINIO\utente</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT4H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</Command>
      <Arguments>-command " &amp; {Send-MailMessage -SMTPServer 127.0.0.1 -To 'info@acme.it' -From 'info@acme.it' -Subject 'BACKUP OK' -Body 'Verificare il backup da Windows server backup.'}"</Arguments>
    </Exec> 
 </Actions>
</Task>

File BackupOK-2012R2.xml

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2012-11-22T10:58:40.4469273</Date>
    <Author>NOMEDOMINIO\utente</Author>
  </RegistrationInfo>
  <Triggers>
    <EventTrigger>
      <Enabled>true</Enabled>
      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Microsoft-Windows-Backup"&gt;&lt;Select Path="Microsoft-Windows-Backup"&gt;*[System[(EventID=4)]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
    </EventTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>NOMEDOMINIO\utente</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT4H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</Command>
      <Arguments>-command " &amp; {Send-MailMessage -SMTPServer 127.0.0.1 -To 'info@acme.it' -From 'info@acme.it' -Subject 'BACKUP OK' -Body 'Backup terminato correttamente.'}"
      </Arguments>
    </Exec> 
  </Actions>
</Task>

Al verificarsi dell’evento di fine backup sarà spedito un messaggio e-mail con l’esito del salvataggio.

Se non avete un server di posta interno vi consigliamo di leggere il nostro post Configurare un SMTP server su Windows 2008 senza Exchange