Child pages
  • Incremental backup Windows PC

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Install FreeFileSync to default folder C:\Program Files\FreeFileSync
  2. Create new folder C:\backup_config
  3. Copy to this folder following files:
    1. backup.bat
    2. SwithMail.exe
    3. BatchRun.ffs_batch
  4. Open in a text editor backup.bat file and edit parameters in top part of the file:
    • Destination folder (ex. \\192.168.28.2\FAMC-GREEN)
    • Network username
    • Network password
    • Name of FreeFileSync profile (keep default one BatchRun.ffs_batch)
    • Retention period, days
    • Global report file location (keep default one "\\192.168.28.2\TH Share\_backup_global_report\backup_global_report.csv")
    • Indicate one or multiple folders to be backed up (ex. C:\Users\FAMC\Desktop)
    • Gmail user that will send reports
    • Gmail password
    • Send email to address
  5. Open Task Scheduler (press Win+К combination and run taskschd.msc)
  6. Import the file backup-on-idle.xml to create new task
  7. Test setup by running the task on demand (right click and run). Check  folders C:\backup_config\batch_logs and C:\backup_config\ffs_logs and read reports.
    • Note that first run might be reported with errors because destination folders are not existed. However destination folders will be created automatically after the first run.

Appendix 1

Backup configuration files

Code Block
languagetext
titlebackup.bat
collapsetrue
:: Created by Daniel da.net@auroville.org.in
:: Install FreeFileSync in default C:\Program Files\FreeFileSync folder
:: Create folder C:\backup_config and copy sample configuration files to it
:: Configure parameters below

@ECHO OFF

:: Path to the destination backup folder either network or local.
:: In case of a network place use format \\SERVER\Folder in case of a local foler use DRIVE_LETTER:\FOLDER
:: Don't put backslash at the end of the line
SET Destination=\\192.168.28.2\FAMC-GREEN

:: Server credentials - in case of network location.
:: If using local folder or public share that doesn't require credentials, keep both fields blank.
SET User=famcbackup
SET Password=htHL678kh

:: Path to FFS profile file
SET FFSProfile=BatchRun.ffs_batch

:: Changed and deleted files retention period
SET retention=30

:: Global report file located in public network location
SET GlobalReportFile="\\192.168.28.2\TH Share\_backup_global_report\backup_global_report.csv"

:: Set folders for backup. Spaces are allowed. No need quote marks. Every location must start with drive letter, colon, backslash (C:\... D:\...).
:: Keep empty or delete lines that are not needed. If needed more location, add more lines using the same format.
SET source[1]=C:\Users\FAMC\Desktop
SET source[2]=
SET source[3]=
SET source[4]=
SET source[5]=
SET source[6]=
SET source[7]=
SET source[8]=
SET source[9]=
SET source[10]=

:: Send email report as:
SET GmailUser=da.info@auroville.org.in
SET GmailPassword="auroville 2018 AV"
SET SendEmailTo=da.net@auroville.org.in

::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::: DON'T EDIT BELOW THIS LINE ::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: Creating TIMESTAMP in good format
FOR /f "tokens=2 delims==" %%a IN ('wmic OS Get localdatetime /value') DO SET "dt=%%a"
SET "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
SET "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
SET "timestamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"

:: Checking if backup was running today already. If yes - go to END (do nothing)
IF EXIST batch_logs\batch_log_%YYYY%-%MM%-%DD%* GOTO END

:: Creating batch log file
IF NOT EXIST "batch_logs" MKDIR "batch_logs"
SET BatchLogFile=batch_logs\batch_log_%timestamp%.txt
ECHO This is backup log created on %timestamp% > %BatchLogFile%

:: Creating FFS log file
IF NOT EXIST "ffs_logs" MKDIR "ffs_logs"
SET FFSLogFile=ffs_logs\ffs_log_%timestamp%.txt
ECHO. > %FFSLogFile%

:: Preparing message for user
ECHO Dear user! > message.txt
ECHO. >> message.txt
ECHO We backup only following folders on this computer >> message.txt
ECHO. >> message.txt

:: Mounting network volume or skipping this if no need to login
IF "%User%"=="" GOTO NOLOGIN
net use %Destination% /user:%User% %Password%
IF ERRORLEVEL 1 (
		ECHO ERROR Mounting network volume %Destination% >> %BatchLogFile%
	) ELSE (
		ECHO OK Mounting network volume %Destination% >> %BatchLogFile%
		)

:NOLOGIN

:: Running cycles that will sync pairs of directories using same FFS profile for each pair separately
SET i=1
SET ErrLevel=0

:LOOP
	SETLOCAL EnableDelayedExpansion
	
	:: Defining Source and Target folders for current cycle run
	IF "!source[%i%]!"=="" GOTO ENDLOOP
	SET Source=!source[%i%]!
	SET Target=!source[%i%]:~0,1!!source[%i%]:~2,150!
	
	:: Running backup for current couple
	"C:\Program Files\FreeFileSync\FreeFileSync.exe" %FFSProfile% -dirpair "%Source%" "%Destination%\%Target%"
	IF ERRORLEVEL 1 (
			ECHO ERROR %Source% %Destination%\%Target% >> %BatchLogFile%
			SET /A ErrLevel+=1
		) ELSE (ECHO OK %Source% %Destination%\%Target% >> %BatchLogFile%)
	
	:: Identifying name of FFS log file that was just created
	SETLOCAL EnableExtensions DisableDelayedExpansion
	SET "LastLog="
	FOR /f "delims=" %%a IN ('DIR /b /o-d ffs_logs\ 2^>NUL') DO (
	IF NOT DEFINED LastLog SET "LastLog=%%a"
	)		
	
	:: Streaming last FFS report into common report file
	TYPE "ffs_logs\%LastLog%" >> %FFSLogFile%
	ECHO.>>%FFSLogFile%
	DEL "ffs_logs\%LastLog%"
	
	:: Adding source folder to user message that will be displayed at the end
	ECHO %Source% >> message.txt
	SET /A i+=1	
	GOTO LOOP
:ENDLOOP

:: Deleting files older than %retention% from backup _modified folder
PUSHD "%Destination%\_modified" &&(
    forfiles -s -m *.* -d -%retention% -c "cmd /c del /s /q @path"
	) & POPD
IF ERRORLEVEL 1 (
	ECHO WARNING Deleting files older than %retention% days from %Destination%\_modified. Nothing to delete >> %BatchLogFile%		
	) ELSE (ECHO OK Deleted files older than %retention% days from %Destination%\_modified. >> %BatchLogFile%)

:: Deleting log file older than %retention% from batch_logs and ffs_logs

forfiles /p "batch_logs" /s /m *.* /d -%retention% /c "cmd /c del @path"
IF ERRORLEVEL 1 (
	ECHO WARNING Deleting batch log files older than %retention% days. Nothing to delete >> %BatchLogFile%		
	) ELSE (ECHO OK Deleted batch log files older than %retention% days. >> %BatchLogFile%)
	
forfiles /p "ffs_logs" /s /m *.* /d -%retention% /c "cmd /c del @path"
IF ERRORLEVEL 1 (
	ECHO WARNING Deleting FFS log files older than %retention% days. Nothing to delete >> %BatchLogFile%		
	) ELSE (ECHO OK Deleted FFS log files older than %retention% days. >> %BatchLogFile%)
	
:: Checking for errors
IF NOT %ErrLevel%==0 GOTO FFSERROR

:: Sending email Backup completed successful
SwithMail.exe /s /from %GmailUser% /name "backup" /pass %GmailPassword% /server "smtp.gmail.com" /p "587" /SSL /to %SendEmailTo% /sub "%COMPUTERNAME% backup OK" /b "Backup completed successful"

GOTO FFSEXIT
			
:FFSERROR

:: Sending email Backup completed with ERROR with %FFSLogFile% %BatchLogFile% in attachment
SwithMail.exe /s /from %GmailUser% /name "backup" /pass %GmailPassword% /server "smtp.gmail.com" /p "587" /SSL /to %SendEmailTo% /sub "%COMPUTERNAME% backup ERROR" /b "Backup completed with errors. See log attached." /a "%FFSLogFile%|%BatchLogFile%"

:FFSEXIT

::Writing to global report CSV file (experimental)
ECHO %YYYY%-%MM%-%DD%,%HH%:%Min%:%Sec%,%COMPUTERNAME%,%ErrLevel% >> %GlobalReportFile%


IF "%User%"=="" GOTO NOLOGOUT	
:: Restartning 	Workstation service to release network share
net stop lanmanworkstation /y
net start lanmanworkstation /y

:NOLOGOUT

::Displaing message to user
ECHO. >> message.txt
ECHO If you want to add more backup locations, please talk to Admin >> message.txt
msg * < message.txt

:END

...

Code Block
languagetext
titlebackup-on-idle.xml
collapsetrue
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2018-06-25T17:09:09.0960454</Date>
    <Author>GREEN\Admin</Author>
    <URI>\backup</URI>
  </RegistrationInfo>
  <Triggers>
    <IdleTrigger>
      <Enabled>true</Enabled>
    </IdleTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-18</UserId>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <Duration>PT5M</Duration>
      <WaitTimeout>PT1H</WaitTimeout>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>true</RunOnlyIfIdle>
    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
    <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\backup_config\backup.bat</Command>
      <WorkingDirectory>C:\backup_config</WorkingDirectory>
    </Exec>
  </Actions>
</Task>

View file
nameSwithMail.exe
height250
View file
nameBatchRun.ffs_batch
height250
View file
namebackup-on-idle.xml
height250
View file
namebackup.bat
height250