You can create a simple batch file (.bat) to back up a folder automatically in Windows. Here’s a step-by-step example:
🔹 Example: Backup one folder to another location
@echo off
set source="C:\MyData"
set destination="D:\Backup\MyData_%date:~-4%-%date:~7,2%-%date:~4,2%"
echo Backing up from %source% to %destination%
xcopy %source% %destination% /E /H /C /I /Y
echo Backup completed!
pause
🔹 Explanation:
-
set source=
→ Source folder you want to back up. -
set destination=
→ Destination folder where backup will be stored.-
%date:~-4%-%date:~7,2%-%date:~4,2%
adds today’s date inYYYY-MM-DD
format to the folder name (so each backup is stored separately).
-
-
xcopy
options:-
/E
→ Copy all subdirectories (including empty ones). -
/H
→ Copy hidden + system files. -
/C
→ Continue even if errors occur. -
/I
→ Assume destination is a folder. -
/Y
→ Suppress overwrite prompts.
-
🔹 Usage:
-
Open Notepad.
-
Paste the code above.
-
Save it as
backup.bat
(choose All Files in Save as type). -
Double-click
backup.bat
to run.
Practical Example
Practical Example:2
@echo off
set source="C:\MyData"
set destination="D:\Backup\MyData_%date:~-4%-%date:~7,2%-%date:~4,2%"
echo Backing up from %source% to %destination%
xcopy %source% %destination% /E /H /C /I /Y
echo Backup completed!
pause
Comments
Post a Comment