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
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Simple Linear Regression

632 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