• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2561
  • Last Modified:

Batch file to create folder YYYYMMDD to backup file

I need some help...

I run a daily backup and I want the job to:

Create a folder YYYYMMDD based on today's date
Backup files to the newly created folder

I've included the my current script below which somebody else wrote.  It currently creates the date folder but as:

Sun 11_05_2008

I'm not very experienced with batch files (I didn't write this one) and I just need the modified code so the folder is created as YYYYMMDD.
@echo off
echo ===============================================================
echo Create folder and backup files
echo ===============================================================
@echo off
md "\\server\backups\%DATE:/=_%"
STSADM -o backup -directory "\\server\backups\%DATE:/=_%" -backupmethod full -overwrite 
echo completed

Open in new window

0
drewberrylicious
Asked:
drewberrylicious
  • 2
  • 2
  • 2
1 Solution
 
drewberryliciousAuthor Commented:
When I run echo %date% - the date I get (per what's currently created by the existing batch file) is Sun 11/09/2008
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
@echo off
echo ===============================================================
echo Create folder and backup files
echo ===============================================================
@echo off
md "\\server\backups\%DATE:~-4%%date:~4,2%%date:~7,2%"
STSADM -o backup -directory "\\server\backups\%DATE:~-4%%date:~4,2%%date:~7,2%" -backupmethod full -overwrite
echo completed
0
 
omarfaridCommented:
try this

@echo off
echo ===============================================================
echo Create folder and backup files
echo ===============================================================
@echo off
md "\\server\backups\%DATE:/=_%"
STSADM -o backup -directory "\\server\backups\%date:~10,4%%date:~4,2%%date:~7,2%" -backupmethod full -overwrite
echo completed
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
Lee W, MVPTechnology and Business Process AdvisorCommented:
omarfarid,

Your answer is essentially the same concept as mine... but won't work because you didn't account for the directory creation area.
0
 
omarfaridCommented:
Well, I concentrated on the date part and basically modified the asker's code
0
 
drewberryliciousAuthor Commented:
Worked like a charm.  Thanks for being so thorough (and quick)!
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now