Delete restore points except recent restore point.

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)

I keep getting an error, but only on some of my endpoints.
Traceback (most recent call last): File “<string>”, line 33, in <module> File “C:\Program Files (x86)\COMODO\Comodo ITSM\lib\re.py”, line 181, in findall return _compile(pattern, flags).findall(string) TypeError: expected string or buffer On a few of them I replaced the re.py file, from a system that it worked on, and it started working. I tried that this time, and it did not work, so I removed the communication software, and reinstalled, thinking that maybe I have a bad update. That did not work either, any ideas??

@BOSS Is there anything in common with ‘some of the endpoints’ that keep getting the error? OS version? Build?

With the upcoming update to the C1 platform, we also advise to check these endpoints again afterwards.

OK, I will check them again on Sunday, I will get alerts, since my monthly maintenance will run tomorrow night, or sunday early morning.

Hi @BOSS ,

Refer this modified script for deleting the restore point except the latest or new restore point,

https://scripts.comodo.com/frontend/web/topic/delete-restore-points-except-recent-restore-point

Thank you.

Same error…

I will look deeper, maybe it is not this part of the script that is failing, but it seems that way. This is the first part of a inclusive procedure, that does a lot of stuff. I will try running the script alone, and see if I get the same results.

Hi @BOSS

We are analyzing your request, and update you once it has been completed
Thank you

Hi @BOSS

Sorry for your inconvenience.Please refer the attached JSON and let us know your feedback to us,

Thank you

20180418-Delete-restore-points-except-recent-restore-point.json (3.9 KB)

This one seemed to of worked, at least on the first run, I will test some more, on systems that worked with the last script, and others that did not work. Thanks.