Daily backup batch file
Moderator: DosItHelp
Daily backup batch file
I'm trying to write a batch file that will create a folder using the current date, then copy a folder of files with sub directories to this folder. I can create the dated folder, but can't figure out how to instruct xcopy to copy everything to the folder that was just created. Anybody have any ideas?
Re: Daily backup batch file
something along the lines of this?
(my xcopy knowledge is more than a bit rusty)
/S = copies all folders and subfolder
/H = copies files with the attributes "hidden" and "system"
(my xcopy knowledge is more than a bit rusty)
Code: Select all
md %date%
xcopy The:\source\folder the:\destination\folder /E /H
/S = copies all folders and subfolder
/H = copies files with the attributes "hidden" and "system"
Last edited by AiroNG on 21 Mar 2015 09:04, edited 1 time in total.
Re: Daily backup batch file
I finally figured it out! Every example I used didn't work, and I realized it was because long filenames and folder names were confusing xcopy. Here is the script I ended up using with no problems:
Works like a charm!
Code: Select all
@echo off
set folder=Backup_%date:~4,2%_%date:~7,2%_%time:~0,2%%time:~3,2%
mkdir E:\ACCOUNTING_BACKUPS\%folder%
echo %folder% created
xcopy z:\Judy\ATRCA6~A\*.* E:\accoun~1\%folder%\ /E /D /C /Y
Works like a charm!
Re: Daily backup batch file
jphahn wrote:I finally figured it out! Every example I used didn't work, and I realized it was because long filenames and folder names were confusing xcopy. Here is the script I ended up using with no problems:
@echo off
set folder=Backup_%date:~4,2%_%date:~7,2%_%time:~0,2%%time:~3,2%
mkdir E:\ACCOUNTING_BACKUPS\%folder%
echo %folder% created
xcopy z:\Judy\ATRCA6~A\*.* E:\accoun~1\%folder%\ /E /D /C /Y
Works like a charm!
Highly doubtful! The problem was probably that your folder names or file names have spaces in them and you didn't bother to put quotes around your file paths.
Re: Daily backup batch file
Squashman is right.
Below is an example of what should work. You can add the long foldername after the judy folder too.
Below is an example of what should work. You can add the long foldername after the judy folder too.
Code: Select all
@echo off
set "folder=Backup_%date:~4,2%_%date:~7,2%_%time:~0,2%%time:~3,2%"
mkdir "E:\ACCOUNTING_BACKUPS\%folder%"
echo "%folder%" created
xcopy "z:\Judy\ATRCA6~A\*.*" "E:\ACCOUNTING_BACKUPS\%folder%\" /E /D /C /Y