Link to home
Start Free TrialLog in
Avatar of Manish
ManishFlag for India

asked on

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.
Avatar of Valleriani
Valleriani
Flag of Sweden image

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

Avatar of Manish

ASKER

in my batch file when I am printing date it is coming like this
 We- 1-/05/20_
why so?
Avatar of Manish

ASKER

I got this
This is because
set date=%date:~0,2%-%date:~3,2%-%date:~6,6%

Yeah, your date format is different then mine, let me see if I can find something, give me a couple!
Avatar of Manish

ASKER

Format is
 Wed 11/05/2008
ASKER CERTIFIED SOLUTION
Avatar of Valleriani
Valleriani
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Manish

ASKER

Although I didnt testing this solution, I got help due to your solution/suggestion..
Thanks.