Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
293 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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 1500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Six Sigma Control Plans

715 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