Last active
April 4, 2016 07:51
-
-
Save numeralnathan/5a5d5ab7f19237940126 to your computer and use it in GitHub Desktop.
An AutoIt script to delete Windows Backups when disk space falls below threshold
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <AutoItConstants.au3> | |
#include <MsgBoxConstants.au3> | |
; This is where the backups are stored | |
Global Const $BACKUP_DIR = "G:\NREYNOLD-LAP" | |
$free = DriveSpaceFree($BACKUP_DIR) | |
; Don't delete backups if more than 60 GB is available (i.e. enough for another new backup directory to be created) | |
if $free > 60 * 1024 then | |
MsgBox($MB_OK, "Delete Backups", "No backups deleted since there is " & Floor($free / 1024) & " GB of free space") | |
exit(0) | |
endif | |
; G:\machine_name is where the backups are stored | |
$find = FileFindFirstFile($BACKUP_DIR & "\Backup Set *") | |
if $find = -1 then | |
MsgBox(0, "Delete Backups", "Unable to find backups at " & $BACKUP_DIR) | |
exit(1) | |
endif | |
$canidate = "ZZZZZ" | |
$count = 0 | |
while true | |
$file = FileFindNextFile($find) | |
if @error then ExitLoop | |
if StringCompare($canidate, $file) > 0 then $canidate = $file | |
$count = $count + 1 | |
wend | |
FileClose($find) | |
$response = MsgBox($MB_YESNO, "Delete Backups", "There is " & Floor($free / 1024) & " GB of free space." & @CRLF & "Delete the backup: " & $canidate & "?") | |
if $response <> $IDYES then Exit | |
$result = DirRemove($BACKUP_DIR & "\" & $canidate, $DIR_REMOVE) | |
if $result = 0 then | |
MsgBox(0, "Delete Backups", "Failed to delete " & $canidate) | |
else | |
MsgBox(0, "Delete Backups", "Deleted " & $canidate) | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment