Page 1 of 1
Daily backup batch file
Posted: 19 Mar 2015 01:44
by jphahn
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
Posted: 20 Mar 2015 14:25
by AiroNG
something along the lines of this?
(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"
Re: Daily backup batch file
Posted: 20 Mar 2015 14:33
by jphahn
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:
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
Posted: 20 Mar 2015 14:49
by Squashman
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
Posted: 21 Mar 2015 06:26
by foxidrive
Squashman is right.
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