Solved

Why is the date not added to the saved folder in the attached code?

Posted on 2011-03-16
31
422 Views
Last Modified: 2012-05-11
I would like to back up the contents of a folder "eDIGSNEW"  into a folder named "eDIGS" on the "F:" drive
with current date and time to be added to the folder each day it is saved.
The attached code runs but does not add the date and time to the folder. How should this code be modified so that the current date is added to the "eDIGSNEW" folder everytime it is saved. Thanks
@echo off
:: variables
set drive=F:\Backup
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%
set backupcmd=xcopy /s /c /d /e /h /i /r /y

%backupcmd% "C:\shared$\eDIGSNEW" "%drive%\eDIGS"

echo Backup Complete!
@pause

Open in new window

0
Comment
Question by:PDSWSS
[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
  • 16
  • 15
31 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 35148775
@echo off
:: variables
set drive=F:\Backup
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%
set backupcmd=xcopy /s /c /d /e /h /i /r /y

md "%drive%\eDIGS_%folder%"

%backupcmd% "C:\shared$\eDIGSNEW" "%drive%\eDIGS_%folder%"

echo Backup Complete!
@pause
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35148792
oops, i put the date on the wrong folder:

@echo off
:: variables
set drive=F:\Backup
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%
set backupcmd=xcopy /s /c /d /e /h /i /r /y

md  "C:\shared$\eDIGSNEW_%folder%"

%backupcmd% "C:\shared$\eDIGSNEW_%folder%" "%drive%\eDIGS"

echo Backup Complete!
@pause
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35149024
actually, the first one may have been right after all -- I'm confused by your last sentence: "...the current date is added to the "eDIGSNEW" folder" - I think you mean the eDIGS folder instead, correct?

I'm adding an echo statement for clarity:

@echo off
::variables
set drive=F:\Backup
set folder=eDIGS_%date:~10,4%_%date:~4,2%_%date:~7,2%
set backupcmd=xcopy/s/c/d/e/h/i/r/y

md "%drive%\%folder%"

@echo %backupcmd%  "C:\shared$\eDIGSNEW"  "%drive%\%folder%"
%backupcmd%  "C:\shared$\eDIGSNEW"  "%drive%\%folder%"

echo Backup Complete!
@pause
0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

Author Comment

by:PDSWSS
ID: 35149235
Yes. That was a mistake. The date should appear on the "eDIGS" folder. Thanks
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35149275
Note that I added eDIGS to the folder variable in my most recent post:  
set folder=eDIGS_%date:~10,4%_%date:~4,2%_%date:~7,2%
0
 

Author Comment

by:PDSWSS
ID: 35149297
What is the meaning of /s /c /d /e /h /i /r /y?  Thanks
0
 

Author Comment

by:PDSWSS
ID: 35149420
Tested your code. Did not add date to the eDIGS Folder.
See error message. I had another folder in the Backup Folder = eDIGS3.15.11

It says the folder it is attempting to create already exists and then creates an eDIGS folder without the date.
Picture-3.png
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 500 total points
ID: 35149449
From the error message, I think you are using the wrong post (the one where I was confused about the target).  Use this one instead:

@echo off
::variables
set drive=F:\Backup
set folder=eDIGS_%date:~10,4%_%date:~4,2%_%date:~7,2%
set backupcmd=xcopy/s/c/d/e/h/i/r/y

md "%drive%\%folder%"

@echo %backupcmd%  "C:\shared$\eDIGSNEW"  "%drive%\%folder%"
%backupcmd%  "C:\shared$\eDIGSNEW"  "%drive%\%folder%"

echo Backup Complete!
@pause
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35149471
To see the meaning of the XCOPY options, do this at a command prompt:

xcopy /?
0
 

Author Comment

by:PDSWSS
ID: 35149491
What is the meaning of these letters    /s /c /d /e /h /i /r /y?
0
 

Author Comment

by:PDSWSS
ID: 35149652
Used your latest code exactly and got exactly the same result =   F:\BAckup\eDIGS

NO DATE is added to the end of the eDIGS folder.  
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35149664
please run this at a command prompt and post the result here:


set folder=eDIGS_%date:~10,4%_%date:~4,2%_%date:~7,2%
echo %folder%
0
 

Author Comment

by:PDSWSS
ID: 35149722
C:\Users\Administrator>

0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35149762
now post the result of this command:

date/t
0
 

Author Comment

by:PDSWSS
ID: 35149879
see attached
Picture-4.png
0
 

Author Comment

by:PDSWSS
ID: 35150630
Any ideas about the issue here?
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35150693
you used the wrong slash:  use / instead of \  as in date/t

You will need to press CTRL-C to break out of the date prompt above (if it is still like that).
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35150712
also, in addition to date/t please re-run the following and paste another screenshot as you did above:

set folder=eDIGS_%date:~10,4%_%date:~4,2%_%date:~7,2%
echo %folder%
0
 

Author Comment

by:PDSWSS
ID: 35151101
Screen shot attached. Thanks
Picture-4.png
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35151220
this is two separate commands:

first run:
set folder=eDIGS_%date:~10,4%_%date:~4,2%_%date:~7,2%

THEN run:
echo %folder%
0
 

Author Comment

by:PDSWSS
ID: 35151312
Screen shot attached -
Picture-2.png
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35151414
That is the expected result.  Do me a favor and cut-n-paste this into a separate batch file and show the result here.  It won't do anything, it just echos the commands.


@echo off
setlocal

::variables
set drive=F:\Backup
set folder=eDIGS_%date:~10,4%_%date:~4,2%_%date:~7,2%
set backupcmd=xcopy/s/c/d/e/h/i/r/y

ECHO md "%drive%\%folder%"

ECHO %backupcmd%  "C:\shared$\eDIGSNEW"  "%drive%\%folder%"
REM  %backupcmd%  "C:\shared$\eDIGSNEW"  "%drive%\%folder%"

REM echo Backup Complete!
REM @pause

Open in new window

0
 

Author Comment

by:PDSWSS
ID: 35151570
I cut and pasted into notepad and saved as a .cmd file. Ran it and it did nothing as you said.  Screen shot of cut and paste is attached. Is that what you are looking for?
Picture-5.png
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35151586
sorry, i get what you are doing now.  I didn't realize you would be double-clicking it.  (I run .cmd files from a command prompt, but either way works.)

Remove the word "REM" before @pause on the last line -- save it and run it again.
0
 

Author Comment

by:PDSWSS
ID: 35151991
I can not cut and paste into the cmd prompt. Can you?
0
 

Author Comment

by:PDSWSS
ID: 35152055
Screen shot attached. Looks like your code works.
Something I forgot to mention. The first time I ran your code, I got a message that it could not be saved because this file already existed and it displayed eDIGS_2011_03_16 in the message. This is very strange since there never was such a file in the F:\backup folder.  I'm going to create another folder and try saving into a different folder.
Thanks,
Picture-1.png
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35152132
Actually, you can cut-n-paste to a command prompt by setting the "Quick Edit" option, but don't worry about that now, it isn't important.

The output shows that the script is working as expected -- assuming you are specifying the correct source directory to be backed up.

Let's try a simpler version that doesn't use all the variables (which aren't really necessary)
@echo off
 setlocal

 set today=%date:~10,4%_%date:~4,2%_%date:~7,2%

 if not exist "C:\shared$\eDIGSNEW\*" echo No files exist in "C:\shared$\eDIGSNEW"  & exit/b

 md "F:\Backup\eDIGS_%today%" >nul

 xcopy/s/c/d/e/h/i/r/y  "C:\shared$\eDIGSNEW"  "F:\Backup\eDIGS_%today%"

 echo Backup Complete!
@pause

Open in new window

0
 

Author Comment

by:PDSWSS
ID: 35152166
Tried to email this about 20 minutes ago but EE site was unavailable.  PROBLEM SOLVED.

Looks like I made a mistake and left out two of the "%"  Sorry about that.  Thought I cut and pasted it in but must not have.

If I could, I'd give you more points for the extra effort you put in.  I appreciate your sticking with this.

Have a great day.
0
 

Author Closing Comment

by:PDSWSS
ID: 35152171
Thanks for the extra effort.
Excellent solution+++
0
 

Author Comment

by:PDSWSS
ID: 35152185
I gave you the highest scores and yet they scored it at 7.8 - very good?
Whatever algorithm they use to calculate the score needs to be updated.
Does not reflect the actual process. Thanks again.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 35152196
no worries, i've never understood the scoring anyway.  :)
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Microservice architecture adoption brings many advantages, but can add intricacy. Selecting the right orchestration tool is most important for business specific needs.
In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

688 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