Skip to content

Conversation

charlie-curtis
Copy link

@charlie-curtis charlie-curtis commented Aug 4, 2025

Incremental Backup Feature - Pull Request Summary

Overview

Added --checkpoint-file functionality to enable incremental backups, significantly reducing backup time for users who run the script regularly. This is an optional flag

Problem Solved

Previously, every run was a full backup, requiring downloading all submissions regardless of whether they had been processed before. This made regular backups slower than necessary.

Solution

The checkpoint feature stores the Unix timestamp of the newest processed submission. Subsequent runs only process submissions newer than the checkpoint, leveraging LeetCode's reverse chronological API ordering to stop early when reaching older submissions.

Key Features

  • Efficient: Stops API pagination early when reaching older submissions
  • Safe: Only updates checkpoint after successful completion of entire script to prevent over-checkpointing
  • User-friendly: Prompts for confirmation when creating new checkpoint files
  • Respects filters: Only updates checkpoint when submissions are actually written (honors --only-accepted, --language, etc.)

Usage

leetcode-export --checkpoint-file ~/.leetcode_checkpoint --only-accepted

Implementation Details

  • Stores Unix timestamps for timezone-agnostic operation
  • Updates checkpoint atomically at end of successful runs only
  • Maintains backward compatibility (optional feature)
  • Comprehensive error handling and logging

This feature makes regular LeetCode backups practical for active users while maintaining the robustness of the existing codebase.

@charlie-curtis charlie-curtis changed the title add support for nested directories add support for incremental updates Aug 5, 2025
if newest_processed_timestamp is None or submission.timestamp > newest_processed_timestamp:
newest_processed_timestamp = submission.timestamp

os.chdir(base_folder)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: this line, combined with the os.makedirs(problem_folder_name, exist_ok=True) above, allows users to specify problem folders that are nested.
As an example, I wanted to partition my problem folders by the difficulty (e.g. Easy, Medium, Hard top level folders)

As in, this command now works
--problem-folder-name '${difficulty}/${question_id}-${title_slug}'.

Example:
leetcode/solutions/Medium/98-validate-binary-search-tree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant