troubleshooting Question

Disk2VHD image backup with automatic removal of old images when backup drive is full

Avatar of SpacedustPL
SpacedustPL asked on
Storage HardwareStorage SoftwareWindows Server 2008
69 Comments1 Solution240 ViewsLast Modified:
I've got the following script that I'm running as scheduled task each day.

It makes a VHD image of C: drive (447 GB) and copy it to F: drive (3,63 TB) and removes old vhd images when there is more than 4 of these.

I would like to modify it so it would take current disk space usage from C drive and compare it with current disk usage of F drive. If there will be less space on F than it's needed to backup whole C then the last image would be removed.

It would be good to use fsutil utility:

C:\Users\Marek>fsutil volume diskfree c:
Całkowita liczba bajtów wolnych           : 244490219520
Całkowita liczba bajtów                   : 480127946752
Całkowita liczba dostępnych bajtów wolnych: 244490219520

C:\Users\Marek>fsutil volume diskfree f:
Całkowita liczba bajtów wolnych           : 324223422464
Całkowita liczba bajtów                   : 4000575385600
Całkowita liczba dostępnych bajtów wolnych: 324223422464

REM A simple backup system using disk2vhd
REM version 1.3, by J.E.B., 2011-02-22
REM requires 'disk2vhd.exe' to be in the path

setLocal EnableDelayedExpansion

REM "DRIVES" can be one drive identifier with colon, multiple separated by spaces,
REM or asterisk for all.  
REM "DEST" can be a drive letter or a UNC.


REM Keep most recent 4 VHD files in DEST, delete the rest

for /f "skip=4 tokens=* delims= " %%a in ('dir/b/o-d %DEST%\*.VHD') do (
del %DEST%\%%a

REM Backup to VHD

cd \
DISK2VHD %DRIVES% %DEST%\%COMPUTERNAME%--%date:~-10,3%%date:~-7,2%%date:~-4,4%.VHD

Tony J
Lead Technical Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 69 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 69 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros