sui_indexer_alt_restorer/
lib.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4mod archives;
5mod snapshot;
6
7use archives::ArchivalCheckpointInfo;
8use clap::Parser;
9use sui_pg_db::DbArgs;
10use url::Url;
11
12use crate::snapshot::SnapshotRestorer;
13
14#[derive(Parser, Debug, Clone)]
15#[clap(name = "sui-indexer-alt-restorer")]
16pub struct Args {
17    /// Restore from end of this epoch.
18    #[clap(long, env = "START_EPOCH", required = true)]
19    pub start_epoch: u64,
20
21    /// Url of the endpoint to fetch snapshot files from,
22    /// for example <https://formal-snapshot.mainnet.sui.io>
23    #[clap(long, env = "ENDPOINT", required = true)]
24    pub endpoint: String,
25
26    /// Bucket to fetch snapshot files from.
27    #[clap(long, env = "SNAPSHOT_BUCKET", required = true)]
28    pub snapshot_bucket: String,
29
30    /// Bucket to fetch archive files from.
31    #[clap(long, env = "ARCHIVE_URL", required = true)]
32    pub archive_url: String,
33
34    /// Local directory to temporarily store snapshot files.
35    #[clap(long, env = "SNAPSHOT_LOCAL_DIR", required = true)]
36    pub snapshot_local_dir: String,
37
38    /// Number of concurrent restore tasks to run.
39    #[clap(long, env = "CONCURRENCY", default_value_t = 50)]
40    pub concurrency: usize,
41
42    /// The URL of the database to connect to.
43    #[clap(
44        long,
45        env = "DATABASE_URL",
46        default_value = "postgres://postgres:postgrespw@localhost:5432/sui_indexer_alt"
47    )]
48    pub database_url: Url,
49
50    /// Database connection arguments from `sui-pg-db`.
51    #[clap(flatten)]
52    pub db_args: DbArgs,
53}
54
55pub async fn restore(args: &Args) -> anyhow::Result<()> {
56    let archival_checkpoint_info =
57        ArchivalCheckpointInfo::read_archival_checkpoint_info(args).await?;
58    let mut snapshot_restorer =
59        SnapshotRestorer::new(args, archival_checkpoint_info.next_checkpoint_after_epoch).await?;
60    snapshot_restorer.restore().await?;
61    Ok(())
62}