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
250 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

A short article about a problem I had getting the GPS LocationListener working.
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
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 …
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now