?
Solved

batch file for backup

Posted on 2008-11-05
7
Medium Priority
?
419 Views
Last Modified: 2012-08-14
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.
0
Comment
Question by:Manish
  • 4
  • 3
7 Comments
 
LVL 7

Expert Comment

by:Valleriani
ID: 22884996
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
 
LVL 11

Author Comment

by:Manish
ID: 22885683
in my batch file when I am printing date it is coming like this
 We- 1-/05/20_
why so?
0
 
LVL 11

Author Comment

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

0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
LVL 7

Expert Comment

by:Valleriani
ID: 22886223
Yeah, your date format is different then mine, let me see if I can find something, give me a couple!
0
 
LVL 11

Author Comment

by:Manish
ID: 22886273
Format is
 Wed 11/05/2008
0
 
LVL 7

Accepted Solution

by:
Valleriani earned 150 total points
ID: 22886442
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
 
LVL 11

Author Closing Comment

by:Manish
ID: 31513463
Although I didnt testing this solution, I got help due to your solution/suggestion..
Thanks.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

749 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