Skip to content

Instantly share code, notes, and snippets.

@bsetmet
Last active October 8, 2018 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsetmet/b0c49774cac0cc8336b64de565ef9a54 to your computer and use it in GitHub Desktop.
Save bsetmet/b0c49774cac0cc8336b64de565ef9a54 to your computer and use it in GitHub Desktop.
Simple Windows .cmd backup routine using robocopy, set this to run on login, or with scheduler
echo off
REM ----------------------------------------------------------
REM set the command terminal wondinw size and color
REM ----------------------------------------------------------
mode con: cols=68 lines=15
color b0
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 monthstamp=%YYYY%%MM%
set datestamp=%YYYY%%MM%%DD%
set timestamp=%HH%%Min%%Sec%
set fullstamp=%datestamp%_%timestamp%
REM ************************ This method will create a new backup folder for every month
set conDestinationFolder="%localappdata%\Backups\%monthstamp%"
set conLogFile="%localappdata%\Backup_Logs\backup_%fullstamp%.txt"
set conLocalWorkingFolder="%localappdata%\Local Working"
set conFlags=/E /PURGE /TEE /r:1 /w:1 /FFT /log:%conLogFile%
md %localappdata%\Backups
md %localappdata%\Backup_Logs
md %conDestinationFolder%
md %conLocalWorkingFolder%
cls
REM ----------------------------------------------------------
REM Copy current backups to previous version
REM ----------------------------------------------------------
Rem ************************BU of Working office Files
robocopy "%appdata%\Microsoft\Word\STARTUP" "%conDestinationFolder%\WordStartup" %conFlags%
robocopy "%appdata%\Microsoft\Excel\XLStart" "%conDestinationFolder%\ExcelStart" %conFlags%
Rem ************************BU of Local Working Files
md "%conDestinationFolder%\Local Working"
robocopy "%localappdata%\Local Working" "%conDestinationFolder%\Local Working" %conFlags%
md "%conDestinationFolder%\Documents"
robocopy "%userprofile%\Documents" "%conDestinationFolder%\Documents" %conFlags%
md "%conDestinationFolder%\Downloads"
robocopy "%userprofile%\Downloads" "%conDestinationFolder%\Downloads" %conFlags%
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment