Skip to content

Instantly share code, notes, and snippets.

@sionta
Last active February 7, 2024 00:34
Show Gist options
  • Save sionta/32e7647cd08a83650049b5e87cd61864 to your computer and use it in GitHub Desktop.
Save sionta/32e7647cd08a83650049b5e87cd61864 to your computer and use it in GitHub Desktop.
/XF
Thumb.db
desktop.ini
/XD
$RECYCLE.BIN
OneDriveTemp
WindowsImageBackup
System Volume Information
@echo off
@title ROBOCOPY - BACKUP SCRIPTS
cd /d "%~dp0"
set "OPTIONS=E /J /IM /IT"
set "EXCLUDE=JOB:exclude_backup.rcj"
:: replace your source path below
set "_INTERNAL=D:"
:: replace your destination path below
set "_EXTERNAL=E:\ResultBackup"
:cli
set "opt=CLI-Backup Options" & call :help
for %%b in (-b backup) do if /i {%1}=={%%b} (
set msg=Backuping
set "SOURCE=%_INTERNAL%"
set "TARGET=%_EXTERNAL%"
) & goto :main
for %%r in (-r revert) do if /i {%1}=={%%r} (
set msg=Reverting
set "SOURCE=%_EXTERNAL%"
set "TARGET=%_INTERNAL%"
if not exist "%_EXTERNAL%" goto :error
) & goto :main
if /i {%1}=={} set "opt=GUI-Backup Options"
:gui
echo %opt%:
echo.
echo. [1] Backup from [%_INTERNAL%] to [%_EXTERNAL%]
echo. [2] Revert from [%_EXTERNAL%] to [%_INTERNAL%]
echo.
choice /c 12 /m "What your choice? "
if %errorlevel% == 1 (
set msg=Backuping
set "SOURCE=%_INTERNAL%"
set "TARGET=%_INTERNAL%"
) & goto :main
if %errorlevel% == 2 (
echo.
set msg=Reverting
set "SOURCE=%_EXTERNAL%"
set "TARGET=%_INTERNAL%"
if not exist "%_EXTERNAL%" goto :error
) & goto :main
goto :EOF
:help
if {%1}=={/?} goto :usage
if {%1}=={-?} goto :usage
if /i {%1}=={-h} goto :usage
if /i {%1}=={help} goto :usage
goto :EOF
:usage
echo %opt%:&echo.
echo. %~n0 [-b ^| backup] from [%_INTERNAL%] to [%_EXTERNAL%]
echo. %~n0 [-r ^| revert] from [%_EXTERNAL%] to [%_INTERNAL%]
goto :EOF
:main
echo. Running %opt% to %msg%...
if not exist "%CD%\*.rcj" call :exclude
ROBOCOPY "%SOURCE%" "%TARGET%" /%OPTIONS% /%EXCLUDE%
attrib -r -s -h "%TARGET%"
goto :EOF
:exclude
( @rem option for /JOB:exclude_backup.rcj
@echo /XF
@echo Thumb.db
@echo desktop.ini
@echo /XD
@echo $RECYCLE.BIN
@echo OneDriveTemp
@echo WindowsImageBackup
@echo System Volume Information
)>"%CD%\exclude_backup.rcj"
goto :EOF
:error
echo. Canceled: [%_EXTERNAL%\] was not FOUND.
if /i {%1}=={} echo.& pause| echo Press any key to EXIT...
goto :EOF
@sionta
Copy link
Author

sionta commented Dec 6, 2021

Preference

Copy Options

For advanced options: ROBOCOPY /?

Options Descriptions
/E copy subdirectories, including Empty ones.
/J copy using unbuffered I/O (recommended for large files).
/XO eXclude Older files.
/IS Include Same files.
/IT Include Tweaked files.
/IM Include Modified files (differing change times).

Silent options

Don’t use this option if you want to display log results.

Options Descriptions
/NS No Size - don’t log file sizes.
/NC No Class - don’t log file classes.
/NP No Progress - don’t display percentage copied.
/NFL No File List - don’t log file names.
/NDL No Directory List - don’t log directory names.
/NJH No Job Header.
/NJS No Job Summary.

Exclude options

Excluded file and folder with options /JOB:file_exclude.rcj.

file_exlcude.rcj

/XF
    Thumb.db
    desktop.ini
/XD
    $RECYCLE.BIN
    OneDriveTemp

More Scripts

date_time_new_folder.bat

if "%time:~0,1%" == " " (set folderdate=0%time:~1,1%) else set folderdate=%time:~0,2%
set "datetime=%date:~6%%date:~3,2%%date:~0,2%_%folderdate%%time:~3,2%"

hide_folder.bat

attrib +r +h "folder_name" @rem hide folder read only
attrib +r +s +h "folder_name" @rem hide folder system

show_folder.bat

attrib -r -h "folder_name" @rem hide folder read only
attrib -r -s -h "folder_name" @rem hide folder system

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment