Hi ,
Please refer the below script for delete the restore point except the latest or new restore point.
This script will display the list of restore points(SYSTEMDRIVE) which are present in your system, if there are an older restore pointS then it will delete all older restore point except the new/latest one which is processed according to date and time.
If there is only one restore point presnt in your system - then it will display “ONLY ONE RESTORE POINT (and) NO OLD RESTORE POINTS PRESENT IN YOUR SYSTEM”
Finally, it will display output as latest/new restore point which is present in your system.
NOTE:
Please run the script as “SYSTEM ADMINISTRATOR”.
Refer the JSON file for execution.
import os
drive= os.environ['SYSTEMDRIVE']
import re
def ecmd(CMD, r=True):
import ctypes
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
def __enter__(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def __exit__(self, type, value, traceback):
if self.success:
self._revert(self.old_value)
from subprocess import PIPE, Popen
with disable_file_system_redirection():
OBJ = Popen(CMD, shell = True, stdout = PIPE, stderr = PIPE)
out, err = OBJ.communicate()
ret=OBJ.returncode
if r:
return ret
else:
if ret==0:
return out
else:
return ret
rp_count=ecmd('vssadmin List Shadows /for=%s'%drive,False)
A=ecmd('vssadmin List Shadows /for=%s'%drive,False)
b=re.findall('(Contents\sof\sshadow\scopy\sset\sID:\s.*)',A)
if rp_count == 1:
print 'No restore points are created in your system'
elif len(b)==1:
print 'ONLY ONE RESTORE POINT (and) NO OLD RESTORE POINTS PRESENT IN YOUR SYSTEM'
else:
print 'RESTORE POINTS PRESENT IN YOUR SYSTEM IS:'
print rp_count
print '
'
#deleteOLD_rp
print 'DELETING OLDEST RESTORE POINTS IN YOUR SYSTEM..........'
print '
'
print 'AFTER REMOVAL OF OLD RESTORE POINTS ..................................'
def ecmd(CMD, r=True):
import ctypes
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
def __enter__(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def __exit__(self, type, value, traceback):
if self.success:
self._revert(self.old_value)
from subprocess import PIPE, Popen
with disable_file_system_redirection():
OBJ = Popen(CMD, shell = True, stdout = PIPE, stderr = PIPE)
out, err = OBJ.communicate()
ret=OBJ.returncode
if r:
return ret
else:
if ret==0:
return out
else:
return ret
for i in range(1,(len(b))):
ecmd('vssadmin delete shadows /for=%s /oldest /quiet'%drive,False)
fin=ecmd('vssadmin List Shadows /for=%s'%drive,False)
print fin
Sample output:
20170703-del_old_restore-point.json (3.87 KB)