-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
222 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
use anyhow::{Context, Result}; | ||
use clap::Parser; | ||
|
||
use super::copy::fslike::FsLike; | ||
use crate::state::State; | ||
|
||
#[derive(Debug, Parser)] | ||
#[clap(about = "Backup files from a deployment to local machine")] | ||
#[group(skip)] | ||
pub struct Options { | ||
#[clap(help = "Deployment name or id")] | ||
pub source: String, | ||
} | ||
|
||
pub async fn handle(options: Options, state: State) -> Result<()> { | ||
let source = FsLike::from_str(&state, &format!("{}:/", options.source)).await?; | ||
|
||
let backup_file = dirs::download_dir() | ||
.or(dirs::home_dir().map(|home| home.join("Downloads"))) | ||
.context("Could not find a download directory")? | ||
.join(format!( | ||
"hop-backup_{}_{}.tar.gz", | ||
options.source, | ||
chrono::Local::now().format("%Y-%m-%d_%H-%M-%S") | ||
)) | ||
.to_string_lossy() | ||
.to_string(); | ||
|
||
let (_, data) = source.read().await?; | ||
|
||
tokio::fs::write(&backup_file, data) | ||
.await | ||
.with_context(|| format!("Could not write to {backup_file}"))?; | ||
|
||
log::info!("Backup saved to {backup_file}"); | ||
|
||
Ok(()) | ||
} | ||
use anyhow::{Context, Result}; | ||
use clap::Parser; | ||
|
||
use super::copy::fslike::FsLike; | ||
use crate::state::State; | ||
|
||
#[derive(Debug, Parser)] | ||
#[clap(about = "Backup files from a deployment to local machine")] | ||
#[group(skip)] | ||
pub struct Options { | ||
#[clap(help = "Deployment name or id")] | ||
pub source: String, | ||
} | ||
|
||
pub async fn handle(options: Options, state: State) -> Result<()> { | ||
let source = FsLike::from_str(&state, &format!("{}:/", options.source)).await?; | ||
|
||
let backup_file = dirs::download_dir() | ||
.or(dirs::home_dir().map(|home| home.join("Downloads"))) | ||
.context("Could not find a download directory")? | ||
.join(format!( | ||
"hop-backup_{}_{}.tar.gz", | ||
options.source, | ||
chrono::Local::now().format("%Y-%m-%d_%H-%M-%S") | ||
)) | ||
.to_string_lossy() | ||
.to_string(); | ||
|
||
let (_, data) = source.read().await?; | ||
|
||
tokio::fs::write(&backup_file, data) | ||
.await | ||
.with_context(|| format!("Could not write to {backup_file}"))?; | ||
|
||
log::info!("Backup saved to {backup_file}"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.