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
281 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
Industry Leaders: 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…

739 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