Last active
April 30, 2020 13:39
-
-
Save janoamaral/b0377c5f3e07bc73036b774f437555e1 to your computer and use it in GitHub Desktop.
Limpieza de backups viejos de Windows
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
#!/usr/bin/env python3 | |
""" | |
Module Docstring | |
""" | |
__author__ = "Alejandro Amaral" | |
__author__ = "Emmanuel Arcumano" | |
__version__ = "0.0.1" | |
__license__ = "MIT" | |
""" | |
USO: | |
limpieza_backup.py /path/al/directorio/raiz | |
Ejemplo: | |
./limpieza_backup.py /var/shares | |
""" | |
import os, sys | |
from datetime import datetime, timedelta | |
from shutil import rmtree | |
def main(baseDir): | |
""" Main entry point of the app """ | |
with os.scandir(baseDir) as entries: | |
for i, entry in enumerate(entries): | |
if not entry.name.startswith('.') and entry.is_dir(): | |
with os.scandir(entry.path) as backupDir: | |
for i, bd in enumerate(backupDir): | |
if not bd.name.startswith('.') and bd.is_dir(): | |
with os.scandir(bd.path) as winback: | |
for i, wb in enumerate(winback): | |
if not wb.name.startswith('.') and wb.is_dir() and wb.name.startswith('Backup Set'): | |
fecha=(datetime.fromtimestamp(wb.stat(follow_symlinks=False).st_mtime)) - datetime.today() | |
# Si el backup tiene más de 90 días limpiarlo. | |
if (fecha.days < -90): | |
print('Eliminando ' + wb.path) | |
# Para depurar es necesario apretar enter para eliminar. Con Ctrl+C se detiene el script | |
#input("Press Enter to continue...") | |
rmtree(wb.path) | |
if __name__ == "__main__": | |
""" This is executed when run from the command line """ | |
main(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment