A little coding challenge for doing image backups

peterh337

Commendable
May 5, 2016
22
0
1,570
1
I have a 4TB USB drive and want to write a 500GB Trueimage backup to it once a week.

So after about 8 it will fill up. Is there some easy way to delete the oldest backup?

It will run as a batch file, triggered by the AT process.

Win7-64.

The invocation of TI from a command line to generate an image backup is not difficult. I am running TI 2010 which works nicely. After TI 2013 the program got very bad. The difficult part is deleting the old .tib files to make space. I would want to delete the oldest .tib file if the free space falls below say 1TB.
 

little_me

Estimable
May 9, 2015
152
1
4,910
57
Well, as far as comparing free space to 1TB goes, the batch scripts seem to run into the problem you mentioned.
Batch files and their variables don't really like 64 bits (and you can't get 1TB with 32 bit)
So unless better alternative can be found, assuming that backup is around 500GB and you have space for 6 (totals to 3TB) you could just go for the "delete older than 6 weeks" route.

Another alternative might be to research if 64 bit powershell could run said batch file better. Problems with that are that as far as quick look goes, powershell has script execution disabled as default for security reasons.

You could probably get around that 32 bit problem by assuming that anything over 1,000,000,000,000 is "close enough to 1TB" and thus just count characters in %FreeSpace% string to see if there are 13 or more. (12 or less would be 999GB or less)
http://stackoverflow.com/questions/5837418/how-do-you-get-the-string-length-in-a-batch-file
Code:
ECHO %strvar%>x&FOR %%? IN (x) DO SET /A strlength=%%~z? - 2&del x
In short.. the ways to get around the problem exist.

Since I'm not all that great at writing scripts, I fear I cannot help more.

Edit: Also the macrium reflect supports creating rescue media, which as far as I assume, if created on target machine, includes all necessary sata/raid/other drivers.
This allows you to boot and restore image from the disk (2nd Hard disk or USB or anything else)
 

little_me

Estimable
May 9, 2015
152
1
4,910
57
http://serverfault.com/questions/68300/check-free-disk-space-using-batch-commands
http://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days

you can use the first one to set variable %FreeSpace% to be the free space in bytes.
you can compare that to 1TB (1024*1024*1024*1024=1,099,511,627,776)
and if it is less, delete oldest file. (assuming 1/week so as you said, older than 6 weeks)
forfiles -p "C:\what\ever" -s -m *.* /D -<number of days> /C "cmd /c del @path"

more specific examples can be found by googling "batch file for <whatever you want to do>"

or.. googling a bit more, use ready script from: http://stackoverflow.com/questions/28466638/batch-script-to-delete-oldest-folder-in-a-given-folder

Code:
:: Preserve only the %MAXBACKUPS% most recent backups.
FOR /f "skip=%MAXBACKUPS% delims=" %%a in (
'dir "..\Backup\*" /t:c /a:d /o:-d /b'
) do (
ECHO More than %MAXBACKUPS% backups found--Deleting "%%a".
ECHO.
rd /s /q "..\Backup\%%a"
)
Edit:
Although that assumes each backup is in it's own subfolder but by altering the dir command and switching rd to del, you could change it to work with files.
As always though, test with dummy files first and not real backups.
 

USAFRet

Splendid
Moderator


Or, use imaging software that does this natively.
Macrium Reflect, on whatever schedule you select, deleting the oldest as directed.
 

peterh337

Commendable
May 5, 2016
22
0
1,570
1
Thanks for that. Just looked it up.

Looks nice.

BUT -

Backups are easy - you can use the oldest version of Trueimage (I have 2008 too; up to 2010 you could install the same S/N on unlimited machines because it didn't online check) because the backup runs via the OS, which is running fine at the time.

The HUGE issue with this stuff is that sometimes you have to restore the backup :) And that is the point at which you need software which supports your HD controller. This is because the machine gets booted from a Trueimage-generated boot CD. That runs some ripoff of Linux to run the restore program.

Trueimage has been kicking around for a few years and they support the common SATA stuff. That is all I use. I have stopped building machines with RAID because half the time the PSU has blown up and taken out the lot. Plus, all the RAID controllers put data in different places on the HD so when you build such a machine you need to buy a spare RAID controller. And Trueimage never supported most RAID controller out of the box; there are variously horrible procedures for creating a customised Linux boot CD with the right drivers.

Unfortunately Trueimage, despite having got loads of $$$ from me over the years, absolutely never provide any support whatsoever! Their forum is almost dead too. I never got any answers on it.

One way to restore a backup done with say TI 2010, onto a machine whose HD controller is not supported by the bootable TI 2010 CD (and that would apply to most SATA controllers ;) ) is to download a trial of a later version of TI, and create a boot CD off that. The trial version gets overwritten by the restored data of course, which is fine. Unfortunately TI blocked this route after TI 2013...

So I need to stick with what works and has been tested with the boot CD and can actually restore the image.

One gotcha is that the boot version of TI has no "validate archive" feature, so...

Also TI 2013 cannot read TI 2010 backups....

One could go an and on... well off topic now :)
 

little_me

Estimable
May 9, 2015
152
1
4,910
57
Well, as far as comparing free space to 1TB goes, the batch scripts seem to run into the problem you mentioned.
Batch files and their variables don't really like 64 bits (and you can't get 1TB with 32 bit)
So unless better alternative can be found, assuming that backup is around 500GB and you have space for 6 (totals to 3TB) you could just go for the "delete older than 6 weeks" route.

Another alternative might be to research if 64 bit powershell could run said batch file better. Problems with that are that as far as quick look goes, powershell has script execution disabled as default for security reasons.

You could probably get around that 32 bit problem by assuming that anything over 1,000,000,000,000 is "close enough to 1TB" and thus just count characters in %FreeSpace% string to see if there are 13 or more. (12 or less would be 999GB or less)
http://stackoverflow.com/questions/5837418/how-do-you-get-the-string-length-in-a-batch-file
Code:
ECHO %strvar%>x&FOR %%? IN (x) DO SET /A strlength=%%~z? - 2&del x
In short.. the ways to get around the problem exist.

Since I'm not all that great at writing scripts, I fear I cannot help more.

Edit: Also the macrium reflect supports creating rescue media, which as far as I assume, if created on target machine, includes all necessary sata/raid/other drivers.
This allows you to boot and restore image from the disk (2nd Hard disk or USB or anything else)
 
Thread starter Similar threads Forum Replies Date
David___Only Apps General Discussion 0
R Apps General Discussion 1
L Apps General Discussion 7
S Apps General Discussion 6
T Apps General Discussion 2
J Apps General Discussion 1
ExtreamChaozZ Apps General Discussion 6
Darkmatterx Apps General Discussion 3
L Apps General Discussion 1
A Apps General Discussion 1
T Apps General Discussion 5
A Apps General Discussion 7
P Apps General Discussion 3
J Apps General Discussion 6
U Apps General Discussion 1
L Apps General Discussion 5
S Apps General Discussion 1
U Apps General Discussion 2
A Apps General Discussion 8
C Apps General Discussion 2

ASK THE COMMUNITY