Oiler Works
  • Home
    • My resume
    • Free premium
    • Privacy Policy
  • Portfolio
  • Blogs
    • Computing
    • Science & MBA
    • Gaveta de remédios
    • Canadá
    • Presentes

backup Server Using Duplicati

25/4/2022

 
Backup system using Duplicati on a segregated Windows notebook.
@echo off

FOR /f "tokens=1 delims=/:" %%a IN ('time /t') DO SET _hour=%%a
FOR /f "delims="            %%a IN ('date /t') DO SET _date=%%a
FOR /f "delims="            %%a IN ('time /t') DO SET _time=%%a
IF "%DUPLICATI__backup_name%"=="Nudox para Local" goto sch1
exit 0

:sch1
        if %_hour% LSS 21 exit 0
        echo %_date% %_time% [%DUPLICATI__backup_name%] Shutdown triggered >> _Scheduler.txt
    shutdown /s /f /t 30 /d p:0:0 /c "Shutdown triggered by finished Duplicati job [%DUPLICATI__backup_name%]"
exit 0

@echo off

REM https://forum.duplicati.com/t/feature-request-better-scheduling-with-duplicati/10964/7
REM Duplicati will run the script before the backup job and waits for its 
REM completion for 60 seconds (default timeout value). After a timeout a 
REM warning is logged and the backup is started.
REM The following exit codes are supported:
REM
REM - 0: OK, run operation
REM - 1: OK, don't run operation
REM - 2: Warning, run operation
REM - 3: Warning, don't run operation
REM - 4: Error, run operation
REM - 5: Error don't run operation
REM - other: Error don't run operation

FOR /f "tokens=1 delims=/:" %%a IN ('time /t') DO SET _hour=%%a
FOR /f "delims="            %%a IN ('date /t') DO SET _date=%%a
FOR /f "delims="            %%a IN ('time /t') DO SET _time=%%a
ping N042018003351 -n 1 -w 1000 | find "TTL=" >nul 2>&1 
SET _ping=%ERRORLEVEL%
IF "%DUPLICATI__backup_name%"=="Digitalizados para Bianca" GOTO sch1
IF "%DUPLICATI__backup_name%"=="Nudox para Bianca" goto sch1
IF "%DUPLICATI__backup_name%"=="Nudox para Local" goto sch2

:sch1
REM Destino Bianca, entre 8 e 17, precisa teste de ping
        if %_hour% LSS 07 goto nobackup
        if %_hour% GEQ 18 goto nobackup
        if %_ping% EQU 1 goto nobackup
        PowerShell -NoProfile -ExecutionPolicy Bypass -file "%~dp0_Desarquivar_antigos.ps1" -days 120 -reset 1
        goto backup

:sch2
REM Destino drive interno, entre 6 e 9, e 16 e 21, quando Bianca deve estar desligado, precisar PS <60 dias
        if %_ping% EQU 0 (
                if %_hour% GEQ 09 (
                        if %_hour% LSS 16 goto nobackup
                )
                if %_hour% LSS 06 goto nobackup
                if %_hour% GEQ 21 goto nobackup
        )
        PowerShell -NoProfile -ExecutionPolicy Bypass -file "%~dp0_Desarquivar_antigos.ps1" -days 45 -reset 1
        goto backup

:backup
if %_ping% EQU 1 echo %_date% %_time% [%DUPLICATI__backup_name%] Backup authorized by no ping>> _Scheduler.txt
echo 0-Backup
exit /b 0

:nobackup
if %_ping% EQU 1 echo %_date% %_time% [%DUPLICATI__backup_name%] Backup denied by no ping>> _Scheduler.txt
echo 1-No backup
exit /b 1

goto:EOF


param($days=60,$reset=0);
[email protected](
"X:\NUDOX\Processados",
"X:\NUDOX\10-SCANNER\Processados",
"X:\NUDOX\31-João Lima",
"X:\NUDOX\34-Euler" );

foreach ($path in $paths) {
        if ($reset -ne 0) {
        #Set Archive for files Normal & CreationTime>=-days
                Get-ChildItem -Path "$path" -Recurse -Force -File -Attributes 'Normal'  | Where-Object { $_.CreationTime -ge (Get-Date).AddDays(-$days) } | ForEach-Object { $_.Attributes = $_.attributes -bor         [System.IO.FileAttributes]::Archive  }
        }
        #Unset Archive for files Archive & CreationTime<-days
                Get-ChildItem -Path "$path" -Recurse -Force -File -Attributes 'Archive' | Where-Object { $_.CreationTime -lt (Get-Date).AddDays(-$days) } | ForEach-Object { $_.attributes = $_.attributes -band (-bnot [System.IO.FileAttributes]::Archive) }
        
}

exit 0


Comments are closed.

    Author

    About Me /\ Sur moi

    View Euler Alves's profile on LinkedIn
Powered by Create your own unique website with customizable templates.
  • Home
    • My resume
    • Free premium
    • Privacy Policy
  • Portfolio
  • Blogs
    • Computing
    • Science & MBA
    • Gaveta de remédios
    • Canadá
    • Presentes