diff --git a/10 Backup/.env b/10 Backup/.env new file mode 100644 index 0000000..9769ce9 --- /dev/null +++ b/10 Backup/.env @@ -0,0 +1,8 @@ +KB_MYSQL_HOST=192.168.1.50 +KB_MYSQL_PORT=3306 +KB_MYSQL_USER=root +KB_MYSQL_PASSWORD=Vlado9674+ +KB_MYSQL_DB=kanboard + +KB_BACKUP_DIR=U:\MySQLBackup\Kanboard +KB_KEEP_DAYS=30 \ No newline at end of file diff --git a/10 Backup/10 KanboardBackup.py b/10 Backup/10 KanboardBackup.py new file mode 100644 index 0000000..48cdca6 --- /dev/null +++ b/10 Backup/10 KanboardBackup.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os +import sys +import gzip +import shutil +import subprocess +from datetime import datetime, timedelta +from pathlib import Path + +PROJECT_ROOT = Path(__file__).resolve().parent.parent +MYSQLDUMP = PROJECT_ROOT / "bin" / "mysqldump.exe" + + +def load_dotenv(dotenv_path: Path) -> None: + if not dotenv_path.exists(): + return + for line in dotenv_path.read_text(encoding="utf-8").splitlines(): + line = line.strip() + if not line or line.startswith("#") or "=" not in line: + continue + k, v = line.split("=", 1) + k = k.strip() + v = v.strip().strip('"').strip("'") + os.environ.setdefault(k, v) + +def require_env(name: str) -> str: + v = os.getenv(name) + if not v: + raise SystemExit(f"Chybí proměnná {name} (dej ji do .env nebo env).") + return v + +def run(cmd: list[str], *, cwd: Path | None = None) -> None: + # pro ladění si můžeš odkomentovat print(cmd) + p = subprocess.run(cmd, cwd=str(cwd) if cwd else None) + if p.returncode != 0: + raise SystemExit(f"Příkaz selhal (exit={p.returncode}): {' '.join(cmd)}") + +def main() -> None: + here = Path(__file__).resolve().parent + load_dotenv(here / ".env") + + host = require_env("KB_MYSQL_HOST") + port = require_env("KB_MYSQL_PORT") + user = require_env("KB_MYSQL_USER") + password = require_env("KB_MYSQL_PASSWORD") + db = require_env("KB_MYSQL_DB") + + backup_dir = Path(os.getenv("KB_BACKUP_DIR", "./backups")).resolve() + keep_days = int(os.getenv("KB_KEEP_DAYS", "30")) + + backup_dir.mkdir(parents=True, exist_ok=True) + + ts = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + sql_path = backup_dir / f"kanboard_{db}_{ts}.sql" + gz_path = backup_dir / f"{sql_path.name}.gz" + + # Bezpečně: vytvoříme dočasný mysql config soubor, aby heslo nebylo v "ps" + cnf_path = backup_dir / f".mysql_{db}_{ts}.cnf" + cnf_path.write_text( + "[client]\n" + f"host={host}\n" + f"port={port}\n" + f"user={user}\n" + f"password={password}\n", + encoding="utf-8" + ) + try: + # omezit práva (na Linuxu/Unraid ok; na Windows to ignoruj) + try: + os.chmod(cnf_path, 0o600) + except Exception: + pass + + # Mysqldump – kompletní pro obnovu + dump_cmd = [ + str(MYSQLDUMP), + f"--defaults-extra-file={str(cnf_path)}", + "--single-transaction", + "--routines", + "--triggers", + "--events", + "--hex-blob", + "--default-character-set=utf8mb4", + "--set-gtid-purged=OFF", + "--databases", db, + ] + + print(f"[OK] Dělám dump DB '{db}' -> {gz_path}") + # Dump do .sql a rovnou gzip + with subprocess.Popen(dump_cmd, stdout=subprocess.PIPE) as proc: + if proc.stdout is None: + raise SystemExit("Nepodařilo se získat stdout z mysqldump.") + with gzip.open(gz_path, "wb", compresslevel=6) as gz: + shutil.copyfileobj(proc.stdout, gz) + rc = proc.wait() + if rc != 0: + raise SystemExit(f"mysqldump selhal (exit={rc}).") + + # Malá kontrola velikosti + size = gz_path.stat().st_size + if size < 200: # hodně hrubé + raise SystemExit(f"Dump je podezřele malý ({size} B) – něco je špatně.") + + # Retence + cutoff = datetime.now() - timedelta(days=keep_days) + for f in backup_dir.glob("kanboard_*_*.sql.gz"): + try: + if datetime.fromtimestamp(f.stat().st_mtime) < cutoff: + f.unlink(missing_ok=True) + except Exception: + pass + + print(f"[OK] Hotovo. Velikost: {size/1024/1024:.2f} MB") + + finally: + try: + cnf_path.unlink(missing_ok=True) + except Exception: + pass + +if __name__ == "__main__": + main() diff --git a/bin/abseil_dll-debug.dll b/bin/abseil_dll-debug.dll new file mode 100644 index 0000000..1b93315 Binary files /dev/null and b/bin/abseil_dll-debug.dll differ diff --git a/bin/abseil_dll.dll b/bin/abseil_dll.dll new file mode 100644 index 0000000..33a6904 Binary files /dev/null and b/bin/abseil_dll.dll differ diff --git a/bin/comerr64.dll b/bin/comerr64.dll new file mode 100644 index 0000000..f87be30 Binary files /dev/null and b/bin/comerr64.dll differ diff --git a/bin/fido2.dll b/bin/fido2.dll new file mode 100644 index 0000000..c3b7b16 Binary files /dev/null and b/bin/fido2.dll differ diff --git a/bin/gssapi64.dll b/bin/gssapi64.dll new file mode 100644 index 0000000..4627248 Binary files /dev/null and b/bin/gssapi64.dll differ diff --git a/bin/jemalloc.dll b/bin/jemalloc.dll new file mode 100644 index 0000000..7f29f9e Binary files /dev/null and b/bin/jemalloc.dll differ diff --git a/bin/k5sprt64.dll b/bin/k5sprt64.dll new file mode 100644 index 0000000..001c65c Binary files /dev/null and b/bin/k5sprt64.dll differ diff --git a/bin/krb5_64.dll b/bin/krb5_64.dll new file mode 100644 index 0000000..6512cad Binary files /dev/null and b/bin/krb5_64.dll differ diff --git a/bin/krbcc64.dll b/bin/krbcc64.dll new file mode 100644 index 0000000..aaaa898 Binary files /dev/null and b/bin/krbcc64.dll differ diff --git a/bin/libcrypto-3-x64.dll b/bin/libcrypto-3-x64.dll new file mode 100644 index 0000000..d257535 Binary files /dev/null and b/bin/libcrypto-3-x64.dll differ diff --git a/bin/libmecab.dll b/bin/libmecab.dll new file mode 100644 index 0000000..8e3de90 Binary files /dev/null and b/bin/libmecab.dll differ diff --git a/bin/libmysql.dll b/bin/libmysql.dll new file mode 100644 index 0000000..0f9fa36 Binary files /dev/null and b/bin/libmysql.dll differ diff --git a/bin/libprotobuf-debug.dll b/bin/libprotobuf-debug.dll new file mode 100644 index 0000000..92c7606 Binary files /dev/null and b/bin/libprotobuf-debug.dll differ diff --git a/bin/libprotobuf-lite-debug.dll b/bin/libprotobuf-lite-debug.dll new file mode 100644 index 0000000..df17e72 Binary files /dev/null and b/bin/libprotobuf-lite-debug.dll differ diff --git a/bin/libprotobuf-lite.dll b/bin/libprotobuf-lite.dll new file mode 100644 index 0000000..536e92f Binary files /dev/null and b/bin/libprotobuf-lite.dll differ diff --git a/bin/libprotobuf.dll b/bin/libprotobuf.dll new file mode 100644 index 0000000..6cada42 Binary files /dev/null and b/bin/libprotobuf.dll differ diff --git a/bin/libsasl.dll b/bin/libsasl.dll new file mode 100644 index 0000000..5fc53b5 Binary files /dev/null and b/bin/libsasl.dll differ diff --git a/bin/libssl-3-x64.dll b/bin/libssl-3-x64.dll new file mode 100644 index 0000000..dbbbd91 Binary files /dev/null and b/bin/libssl-3-x64.dll differ diff --git a/bin/mysqldump.exe b/bin/mysqldump.exe new file mode 100644 index 0000000..f5a65ba Binary files /dev/null and b/bin/mysqldump.exe differ diff --git a/bin/xpprof64.dll b/bin/xpprof64.dll new file mode 100644 index 0000000..20cee92 Binary files /dev/null and b/bin/xpprof64.dll differ