Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python3
import os.path
import os
from datetime import datetime, timedelta
from pathlib import Path
BASE = "/etc/letsencrypt/"
in_use = dict()
live_dir = os.path.join(BASE, "live")
for domain in os.listdir(live_dir):
domain_dir = os.path.join(live_dir, domain)
if not os.path.isdir(domain_dir):
for certlink in os.listdir(domain_dir):
f = os.path.join(domain_dir, certlink)
target = Path(f).resolve()
print("->", target)
in_use[target] = 1
keep = 0
delete = 0
archive_dir = os.path.join(BASE, "archive")
for domain in os.listdir(archive_dir):
domain_dir = os.path.join(archive_dir, domain)
if not os.path.isdir(domain_dir):
for certfile in os.listdir(domain_dir):
f = Path(os.path.join(domain_dir, certfile))
if f in in_use:
print(f, "is in use. don't delete")
keep += 1
print(f, "is safe to delete")
delete += 1
print("keep:", keep)
print("delete:", delete)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.