Advertisement
FreeBooter

Incremental_Backup

Mar 24th, 2019
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.60 KB | None | 0 0
  1. @echo off
  2. :: Incremental_Backup.bat Created by Hackoo on 12/08/2017
  3. :: It is a total copy first and then incrementally,
  4. :: ie, it just copies the new files and changed files.
  5. mode con cols=95 lines=5 & color 0E
  6. Title %~nx0 for Incremental Backup with XCopy Command by Hackoo 2017
  7. set "Settings=%~dp0Settings.ini"
  8. Set "FirstFull_CopyLog=%~dp0%~n0_FirstFull_CopyLog.txt"
  9. Set "LogFile=%~dp0%~n0_Incremental_CopyLog.txt"
  10. If not exist "%Settings%" (
  11.     Call :BrowseForFolder "Please choose the source folder for the backup" SourceFolder
  12.     Setlocal EnableDelayedExpansion
  13.     If defined SourceFolder (
  14.         echo(
  15.         echo             You chose "!SourceFolder!" as source folder
  16.     ) else (
  17.         echo(
  18.         Color 0C & echo                    The source folder is not defined ... Exiting ......
  19.         Timeout /T 2 /nobreak>nul & exit
  20.     )
  21.     Call :BrowseForFolder "Please choose the target folder for the backup" TargetFolder
  22.     If defined TargetFolder (
  23.         echo(
  24.         echo             You chose "!TargetFolder!" as Target folder
  25.     ) else (
  26.         echo(
  27.         Color 0C & echo                    The Target folder is not defined ... Exiting ......
  28.         Timeout /T 2 /nobreak>nul & exit
  29.     )
  30. Timeout /T 3 /nobreak>nul
  31.     (
  32.         echo "!SourceFolder!"
  33.         echo "!TargetFolder!\Backups_%ComputerName%\"
  34.     )
  35. cls & echo( & echo(
  36. echo         Please wait a while ... The Backup to "!TargetFolder!" is in progress...
  37. Call :Backup_XCopy "!SourceFolder!" "!TargetFolder!" "!FirstFull_CopyLog!"
  38. Timeout /T 1 /nobreak>nul
  39. Start "" "!FirstFull_CopyLog!" & exit
  40. ) else (
  41. Setlocal EnableDelayedExpansion
  42. for /f "delims=" %%a in ('Type "%Settings%"') do (
  43.     set /a idx+=1
  44.     set Param[!idx!]=%%a
  45. )
  46.  
  47. Set "SourceFolder=!Param[1]!"
  48. Set "TargetFolder=!Param[2]!"
  49. echo(
  50. echo        The source Folder from Settings.ini is : !SourceFolder!
  51. echo        The Target Folder from Settings.ini is : !TargetFolder!
  52. Timeout /T 1 /nobreak>nul & cls & echo( & echo(
  53. echo       Please wait a while ... The Backup to !TargetFolder! is in progress...
  54. Call :Backup_XCopy !SourceFolder! !TargetFolder! !LogFile!
  55. )
  56. Timeout /T 1 /nobreak>nul
  57. Start "" !LogFile! & exit
  58. ::****************************************************************************
  59. :BrowseForFolder
  60. set "psCommand="(new-object -COM 'Shell.Application')^
  61. .BrowseForFolder(0,'%1',0,0).self.path""
  62. for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "%2=%%I"
  63. exit /b
  64. ::****************************************************************************
  65. :Backup_XCopy <Source> <Target> <LogFile>
  66. Xcopy /c  /d  /e  /s  /i  /y %1 %2 > %3 2>&1
  67. Exit /b
  68. ::****************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement