Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add script to create s3 snapshots #659

Merged
merged 1 commit into from
Aug 30, 2024
Merged

chore: add script to create s3 snapshots #659

merged 1 commit into from
Aug 30, 2024

Conversation

zakir-code
Copy link
Contributor

@zakir-code zakir-code commented Aug 30, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new automated script for creating and managing blockchain snapshots, enhancing backup efficiency and system maintenance.
  • Improvements

    • Added checks for Docker container status, blockchain synchronization, and disk space availability to ensure reliable snapshot creation.
    • Implemented automatic management of old snapshots in S3, improving storage management.

Copy link

coderabbitai bot commented Aug 30, 2024

Walkthrough

The changes introduce a new script, snapshot.sh, that automates the creation and management of blockchain snapshots using Docker and AWS S3. The script sets up necessary environment variables, checks for required tools, verifies Docker container status, prunes data, creates a snapshot, uploads it to S3, and manages old snapshots. It also updates the Docker container's data directory with the latest blockchain state.

Changes

Files Change Summary
contrib/scripts/snapshot.sh Added a script to automate blockchain snapshot creation, management, and S3 upload.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SnapshotScript
    participant Docker
    participant S3

    User->>SnapshotScript: Run snapshot.sh
    SnapshotScript->>Docker: Check container status
    Docker-->>SnapshotScript: Container running
    SnapshotScript->>SnapshotScript: Verify synchronization
    SnapshotScript->>SnapshotScript: Check disk space
    SnapshotScript->>Docker: Prune blockchain data
    SnapshotScript->>SnapshotScript: Create compressed snapshot
    SnapshotScript->>S3: Upload snapshot
    SnapshotScript->>S3: Upload MD5 checksum
    SnapshotScript->>S3: Manage old snapshots
    SnapshotScript->>Docker: Reset data directory
Loading

Poem

🐇 In the meadow, snapshots bloom,
A script to clear the cluttered room.
With Docker's dance and S3's flight,
We save our world, both day and night.
So hop along, let data flow,
A rabbit's cheer for changes that grow! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@zakir-code zakir-code merged commit 017c6f7 into main Aug 30, 2024
4 checks passed
@zakir-code zakir-code deleted the zakir/snapshot branch August 30, 2024 02:02
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 48fcc94 and cf21256.

Files selected for processing (1)
  • contrib/scripts/snapshot.sh (1 hunks)
Additional comments not posted (22)
contrib/scripts/snapshot.sh (22)

1-4: LGTM!

The shebang and initial comments are appropriate and provide useful information.


6-6: LGTM!

Using set -euo pipefail is a best practice for bash scripts to ensure robustness.


8-14: LGTM!

The environment variable exports and debug setting are appropriate and provide flexibility.


16-22: LGTM!

The S3 bucket ACL retrieval and variable initializations are appropriate and necessary for the script's functionality.


23-24: LGTM!

The OS check for Linux is necessary to ensure compatibility with the script's requirements.


26-31: LGTM!

The installation of required tools (jq, curl, unzip) ensures that the necessary tools are available for the script to function correctly.


33-39: LGTM!

The installation of AWS CLI ensures that the AWS CLI is available for interacting with S3.


41-43: LGTM!

The disk space check ensures that there is enough disk space for the snapshot process.


45-46: LGTM!

The Docker container existence check ensures that the Docker container is available for the snapshot process.


48-49: LGTM!

The node catching up check ensures that the node is fully synchronized before creating a snapshot.


51-52: LGTM!

The upgrade-info.json existence check ensures that the upgrade information is available before creating a snapshot.


54-57: LGTM!

The recreation of the S3 directory ensures that it is clean and available for the snapshot process.


61-70: LGTM!

The Docker container stop and wait logic ensures that the Docker container is properly stopped before proceeding with the snapshot process.


72-86: LGTM!

The data pruning and compression logic ensures that the snapshot size is minimized and the data is in a consistent state.


88-89: LGTM!

The MD5 checksum calculation ensures that the integrity of the snapshot can be verified.


91-93: LGTM!

The S3 upload logic ensures that the snapshot is stored in S3 for later retrieval.


95-97: LGTM!

The S3 ACL setting logic ensures that the appropriate permissions are set for the uploaded files.


99-107: LGTM!

The old snapshot cleanup logic ensures that old snapshots are removed to save storage space.


109-113: LGTM!

The data reset logic ensures that the data directory is clean and ready for the next snapshot process.


115-121: LGTM!

The state sync configuration update logic ensures that the state sync configuration is up-to-date for the next run.


123-124: LGTM!

The Docker container restart logic ensures that the Docker container is running and ready for the next run.


126-126: LGTM!

The completion message provides a clear indication that the script has completed successfully.

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