File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
332347impl 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
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ pub mod create;
77pub mod database;
88pub mod deploy;
99pub mod deployment;
10+ pub mod dump;
1011pub mod index;
1112pub mod listen;
1213pub mod provider_checks;
You can’t perform that action at this time.
0 commit comments