Solved

Can I write a batch file to backup a folder where it automatically enters that day's date?

Posted on 2008-06-22
8
268 Views
Last Modified: 2010-04-16
This is the current code:

xcopy "\\Server\databases\" "E:\Backup\Databases\" /D /V /G /H /R /K /Y /E

so could it say:

xcopy "\\Server\databases\" "E:\Backup06222008\Databases\" /D /V /G /H /R /K /Y /E
0
Comment
Question by:Bert2005
  • 5
  • 2
8 Comments
 
LVL 22

Expert Comment

by:cookre
ID: 21856629
XP has the %DATE% environment variable, but in has embedded slashes.

Here's an example of editing %date% to extract just the digits:

http://www.computing.net/answers/dos/dos-batch-line-to-rename-with-date/16193.html
0
 
LVL 1

Author Comment

by:Bert2005
ID: 21857543
That looks good. Of course, I will try it tonight. Thanks.
0
 
LVL 1

Author Comment

by:Bert2005
ID: 21862029
Sorry, not that good at this.

So, if I wrote:

xcopy "\\Server\databases\" "E:\Backup\Databases\Databases" /D /V /G /H /R /K /Y /E    so that there would be a folder named "databases" inside the main folder "databases" the data would be copied from \\Server\databases to the subfolder databases. And, if I wanted to make the subfolder dated (don't need time) would I do something like

xcopy "\\Server\databases\" "E:\Backup\Databases\D=Databases Echo %date%" /D /V /G /H /R /K /Y /E

I doubt that is close but I was thinking Ihad to name whether I was dating a file or directory. Is this even close?
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 1

Expert Comment

by:phibersg
ID: 21880804
Do this is a DOS batch file,

Every statement in one line..

if not exist "e:\backup%date:~0,2%%date:~3,2%%date:~6,4%\databases" md "e:\backup%date:~0,2%%date:~3,2%%date:~6,4%\databases"

xcopy "\\Server\databases\" "e:\backup%date:~0,2%%date:~3,2%%date:~6,4%\databases" /D /V /G /H /R /K /Y /E
0
 
LVL 1

Accepted Solution

by:
phibersg earned 500 total points
ID: 21880813
Sorry. use this.. it's easier.. :)

and it's a 1-liner.. you need to add /I to the xcopy command..

xcopy "\\Server\databases\" "e:\backup%date:~0,2%%date:~3,2%%date:~6,4%\databases" /D /V /G /H /R /K /Y /E /I
0
 
LVL 1

Author Comment

by:Bert2005
ID: 21880814
Thanks phibersq,

I will try tomorrow. Getting late her now, and I would most likely copy it wrong. :-)
0
 
LVL 1

Author Comment

by:Bert2005
ID: 21880820
Yes, that looks so much easier I may even be able to try it tonight. But, I still will wait until tomorrow. Have a nice night.

Thank you.

Bert
0
 
LVL 1

Author Comment

by:Bert2005
ID: 21888456
Sorry to change the directories and folders in midstream, but I have a couple of batch files, and I used it on the one below. Instead of Databases, I am backing up Amazing Charts and instead of the designation folder being named "backup" it is called "Batch"

So, I am trying to save the folder "Amazing Charts" in the backup folder called "Batch"  Which, of course, should have the date. So, I substituted using your code below:

xcopy "\\Server\Amazing Charts\" "E:\Batch%date:~0,2%%date:~3,2%%date:~6,4%\Amazing Charts" /D /V /G /H /R /K /Y /E /I

It did the backup. The result was it was not saved into the E:\Batch folder, but rather a new folder was made called:

"BatchFr 0"    which contained   a folder called   "27"       which contained  "Amazing Charts"

So, very close. I definitely need the folder called 27, to say 06272008 or any combination thereof.

Thanks.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question