We help IT Professionals succeed at work.

backup batch script

327 Views
Last Modified: 2012-05-05
Hello

I have a very simple backup script like this:

@echo off
echo Copy Zotero
rem xcopy /S /Y /D u:\Library\"Application Support"\Firefox\Profiles\cxcwvb7n.default\zotero c:\zoterobackup
xcopy /S /Y /D u:\desktop\"zotero Super Duper night backup" c:\zoterobackup
pause
echo Done
pause

but I would like to add option so the script creates folder with a different name like backup1, backup2 and so on and copies the files tehre, so I can keep copies of previous backups. Right now it just overwrites the previous one, but if the current backup copies a corrupt DB then my backup is useless

Thanks
-Peter
Comment
Watch Question

CERTIFIED EXPERT

Commented:
How about using the date in the folder name?  Always backup to c:\zoterobackup but before doing this rename it using the date:

for /f "tokens=1-6 delims=/:." %%t in ('echo %date:~4%.%time: =0%') do  ren  c:\zoterobackup  c:\zoterobackup_%%v%%t%%u_%%w%%x%%y
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2006
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Lee W, MVPTechnology and Business Process Advisor
CERTIFIED EXPERT
Most Valuable Expert 2013
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
both work great!!! thanks

where can I find some more explanation about the "token" and "delims" thing, just want to understand what exactly they do
CERTIFIED EXPERT
Top Expert 2006

Commented:
Open command prompt and type

for /?
CERTIFIED EXPERT

Commented:
^
In addition to this, we also used substring substitution of certain characters (like spaces or / or : in the date/time).  To see more about how this works, type

  set /?

Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.