Skip to content

Instantly share code, notes, and snippets.

@Esl1h
Created September 6, 2021 14:16
Show Gist options
  • Save Esl1h/cddf9872ef62a56409bef5076a9e418d to your computer and use it in GitHub Desktop.
Save Esl1h/cddf9872ef62a56409bef5076a9e418d to your computer and use it in GitHub Desktop.
simple batch script to backup folders and files in Windows hosts to another drive or network
@echo
set source=C:\
set destination=\\servername\d$
set command=xcopy /c /d /e /f /g /h /i /r /s /y
set log=D:\backup_log_file.txt
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
echo # # # Starting files %mydate% at %mytime% >> %log%
%command% "%source%\My_Backups" "%destination%\Backups" >> %log%
echo # # %mydate% at %mytime% Complete! >> %log%
:: xcopy /c /d /e /g /h /i /r /s /y "C:\My_Backups" "\\servername\d$\Backups" >> D:\backup_log_file.txt
:: Alternative to xcopy: robocopy, copy, copy-item (PowerShell)
:: To use 'forfiles' command to copy all files except that was created today?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment