batch file for backup

I want batch file which will copy   tar from one folder to another with date time attahed to it
ex..folder1/a.tar to  folder2/a_date_time.tar

Thanks for suggestions.
LVL 11
ManishLeadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VallerianiCommented:
How about this? Changing the file name would be more of an issue to do because of the extention. This is a bit cleaner as well.. Apologizes if its not exactly what you want.

You set the folder to get .tar files, and backup folder. It will copy them like C:\Backup\11-04-08_11-37\filename.tar.. etc

so month-date-year_time (can't use : in files)
@echo off
:: variables
set folder=C:\TEST
set files=*.tar
set bfolder=C:\Backup
set date=%date:~0,2%-%date:~3,2%-%date:~6,6%_
for /f "tokens=1-5 delims=:" %%d in ("%time%") DO SET time=%%d-%%e
 
echo ### Backing up directory...
xcopy /s /c /d /e /h /i /r /y "%folder%\%files%" "%bfolder%\%date%%time%\%
 
files%"
echo Backup Complete! - Saved to %bfolder%\%date%%time%\"
@pause

Open in new window

0
ManishLeadAuthor Commented:
in my batch file when I am printing date it is coming like this
 We- 1-/05/20_
why so?
0
ManishLeadAuthor Commented:
I got this
This is because
set date=%date:~0,2%-%date:~3,2%-%date:~6,6%

0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

VallerianiCommented:
Yeah, your date format is different then mine, let me see if I can find something, give me a couple!
0
ManishLeadAuthor Commented:
Format is
 Wed 11/05/2008
0
VallerianiCommented:
Try this, just to see if this works.
@echo off
SETLOCAL
 
:: variables
set folder=C:\TEST
set files=*.tar
set bfolder=C:\Backup
 
:: Store current date in a variable in default Locale format
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET DATE=%%B
SET DATE=%DATE:/=-%
 
for /f "tokens=1-5 delims=:" %%d in ("%time%") DO SET time=%%d-%%e
 
echo ### Backing up directory...
xcopy /s /c /d /e /h /i /r /y "%folder%\%files%" "%bfolder%\%date%_%time%\%files%"
echo Backup Complete! - Saved to %bfolder%\%date%_%time%"
@pause

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ManishLeadAuthor Commented:
Although I didnt testing this solution, I got help due to your solution/suggestion..
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.