import os import sys import shutil import datetime def create_snapshot(file_path): """ Creates a timestamped backup of the given file in .hmcmkit/backups/ """ if not os.path.exists(file_path): print(f"❌ Error: File not found: {file_path}") return None # Determine paths hmcmkit_root = ".hmcmkit" backup_dir = os.path.join(hmcmkit_root, "backups") os.makedirs(backup_dir, exist_ok=True) # Generate timestamped name timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") filename = os.path.basename(file_path) backup_name = f"{timestamp}_{filename}" backup_path = os.path.join(backup_dir, backup_name) try: shutil.copy2(file_path, backup_path) print(f"📦 Snapshot created: {backup_path}") return backup_path except Exception as e: print(f"❌ Snapshot failed: {e}") return None if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: python snapshot.py ") sys.exit(1) create_snapshot(sys.argv[1])