Skip to content

Commit 9af691d

Browse files
committed
node: Add graphman dump command
Wire the dump subcommand into graphman CLI. Takes a deployment search argument and an output directory, resolves the deployment, and delegates to SubgraphStore::dump().
1 parent 0772110 commit 9af691d

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

node/src/bin/manager.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,21 @@ pub enum Command {
327327
#[clap(long, short, default_value = "http://localhost:8020")]
328328
url: String,
329329
},
330+
331+
/// Dump a subgraph deployment into a directory
332+
///
333+
/// EXPERIMENTAL - NOT FOR PRODUCTION USE
334+
///
335+
/// This will create a dump of the subgraph deployment in the specified
336+
/// directory. The dump includes the subgraph manifest, the mapping, and
337+
/// the data in the database as parquet files. The dump can be used to
338+
/// restore the subgraph deployment later with the `restore` command.
339+
Dump {
340+
/// The deployment (see `help info`)
341+
deployment: DeploymentSearch,
342+
/// The name of the directory to dump to
343+
directory: String,
344+
},
330345
}
331346

332347
impl Command {
@@ -1732,6 +1747,16 @@ async fn main() -> anyhow::Result<()> {
17321747

17331748
commands::deploy::run(subgraph_store, deployment, name, url).await
17341749
}
1750+
1751+
Dump {
1752+
deployment,
1753+
directory,
1754+
} => {
1755+
let (store, primary_pool) = ctx.store_and_primary().await;
1756+
let subgraph_store = store.subgraph_store();
1757+
1758+
commands::dump::run(subgraph_store, primary_pool, deployment, directory).await
1759+
}
17351760
}
17361761
}
17371762

node/src/manager/commands/dump.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::fs;
2+
use std::sync::Arc;
3+
4+
use graph::{bail, prelude::anyhow::Result};
5+
6+
use graph_store_postgres::{ConnectionPool, SubgraphStore};
7+
8+
use crate::manager::deployment::DeploymentSearch;
9+
10+
pub async fn run(
11+
subgraph_store: Arc<SubgraphStore>,
12+
primary_pool: ConnectionPool,
13+
deployment: DeploymentSearch,
14+
directory: String,
15+
) -> Result<()> {
16+
let directory = fs::canonicalize(&directory)?;
17+
let stat = fs::metadata(&directory)?;
18+
19+
if !stat.is_dir() {
20+
bail!(
21+
"The path `{}` is not a directory",
22+
directory.to_string_lossy()
23+
);
24+
}
25+
26+
let loc = deployment.locate_unique(&primary_pool).await?;
27+
28+
subgraph_store.dump(&loc, directory).await?;
29+
Ok(())
30+
}

node/src/manager/commands/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod create;
77
pub mod database;
88
pub mod deploy;
99
pub mod deployment;
10+
pub mod dump;
1011
pub mod index;
1112
pub mod listen;
1213
pub mod provider_checks;

0 commit comments

Comments
 (0)