Daily backup batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jphahn
Posts: 2
Joined: 19 Mar 2015 01:34

Daily backup batch file

#1 Post by jphahn » 19 Mar 2015 01:44

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?

AiroNG
Posts: 46
Joined: 17 Nov 2013 15:00
Location: Germany

Re: Daily backup batch file

#2 Post by AiroNG » 20 Mar 2015 14:25

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"
Last edited by AiroNG on 21 Mar 2015 09:04, edited 1 time in total.

jphahn
Posts: 2
Joined: 19 Mar 2015 01:34

Re: Daily backup batch file

#3 Post by jphahn » 20 Mar 2015 14:33

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!

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Daily backup batch file

#4 Post by Squashman » 20 Mar 2015 14:49

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Daily backup batch file

#5 Post by foxidrive » 21 Mar 2015 06:26

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

Post Reply