summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-12-30 13:26:33 +0000
committerLars Wirzenius <liw@liw.fi>2020-12-30 13:26:33 +0000
commitd590b44ed1481702188f9e540adf85192690333c (patch)
tree682655b00b49a3ad477cfee0b4271344e30b3170
parent6b9553945683e2b01404673e37e8b951b32a993e (diff)
parent6bc74795a009a35a0c1a27426b619b9f20a2db8e (diff)
downloadobnam2-d590b44ed1481702188f9e540adf85192690333c.tar.gz
Merge branch 'latest' into 'main'
Restore latest See merge request larswirzenius/obnam!48
-rw-r--r--obnam.md23
-rw-r--r--src/client.rs5
-rw-r--r--src/cmd/list.rs5
-rw-r--r--src/cmd/restore.rs10
-rw-r--r--src/generation.rs1
-rw-r--r--src/lib.rs2
-rw-r--r--subplot/client.py12
-rw-r--r--subplot/client.yaml3
8 files changed, 53 insertions, 8 deletions
diff --git a/obnam.md b/obnam.md
index 6706fb7..c3b03a8 100644
--- a/obnam.md
+++ b/obnam.md
@@ -896,6 +896,29 @@ given a manifest of the directory live restored in rest in rest.yaml
then files live.yaml and rest.yaml match
~~~
+## Restore latest generation
+
+This scenario verifies that the latest backup generation can be
+specified with literal string "latest". It makes two backups, which
+are different.
+
+~~~scenario
+given an installed obnam
+and a running chunk server
+and a client config based on metadata.yaml
+
+given a file live/data.dat containing some random data
+when I run obnam --config metadata.yaml backup
+
+given a file live/more.dat containing some random data
+and a manifest of the directory live in second.yaml
+when I run obnam --config metadata.yaml backup
+
+when I invoke obnam --config metadata.yaml restore latest rest
+given a manifest of the directory live restored in rest in rest.yaml
+then files second.yaml and rest.yaml match
+~~~
+
diff --git a/src/client.rs b/src/client.rs
index adca373..ec99134 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -6,6 +6,7 @@ use crate::chunkid::ChunkId;
use crate::chunkmeta::ChunkMeta;
use crate::fsentry::{FilesystemEntry, FilesystemKind};
use crate::generation::FinishedGeneration;
+use crate::genlist::GenerationList;
use chrono::{DateTime, Local};
use log::{debug, error, info, trace};
use reqwest::blocking::Client;
@@ -181,7 +182,7 @@ impl BackupClient {
Ok(chunk_ids)
}
- pub fn list_generations(&self) -> anyhow::Result<Vec<FinishedGeneration>> {
+ pub fn list_generations(&self) -> anyhow::Result<GenerationList> {
let url = format!("{}?generation=true", &self.chunks_url());
trace!("list_generations: url={:?}", url);
let req = self.client.get(&url).build()?;
@@ -195,7 +196,7 @@ impl BackupClient {
.iter()
.map(|(id, meta)| FinishedGeneration::new(id, meta.ended().map_or("", |s| s)))
.collect();
- Ok(finished)
+ Ok(GenerationList::new(finished))
}
pub fn fetch_chunk(&self, chunk_id: &ChunkId) -> anyhow::Result<DataChunk> {
diff --git a/src/cmd/list.rs b/src/cmd/list.rs
index 70aa0a7..8766e34 100644
--- a/src/cmd/list.rs
+++ b/src/cmd/list.rs
@@ -3,9 +3,8 @@ use crate::client::{BackupClient, ClientConfig};
pub fn list(config: &ClientConfig) -> anyhow::Result<()> {
let client = BackupClient::new(&config.server_url)?;
- let mut generations = client.list_generations()?;
- generations.sort_by_cached_key(|gen| gen.ended().to_string());
- for finished in generations {
+ let generations = client.list_generations()?;
+ for finished in generations.iter() {
println!("{} {}", finished.id(), finished.ended());
}
diff --git a/src/cmd/restore.rs b/src/cmd/restore.rs
index dd7ed41..9e137f2 100644
--- a/src/cmd/restore.rs
+++ b/src/cmd/restore.rs
@@ -1,5 +1,6 @@
use crate::client::BackupClient;
use crate::client::ClientConfig;
+use crate::error::ObnamError;
use crate::fsentry::{FilesystemEntry, FilesystemKind};
use crate::generation::NascentGeneration;
use indicatif::{ProgressBar, ProgressStyle};
@@ -14,7 +15,7 @@ use std::path::{Path, PathBuf};
use structopt::StructOpt;
use tempfile::NamedTempFile;
-pub fn restore(config: &ClientConfig, gen_id: &str, to: &Path) -> anyhow::Result<()> {
+pub fn restore(config: &ClientConfig, gen_ref: &str, to: &Path) -> anyhow::Result<()> {
// Create a named temporary file. We don't meed the open file
// handle, so we discard that.
let dbname = {
@@ -24,6 +25,13 @@ pub fn restore(config: &ClientConfig, gen_id: &str, to: &Path) -> anyhow::Result
};
let client = BackupClient::new(&config.server_url)?;
+
+ let genlist = client.list_generations()?;
+ let gen_id: String = match genlist.resolve(gen_ref) {
+ None => return Err(ObnamError::UnknownGeneration(gen_ref.to_string()).into()),
+ Some(id) => id,
+ };
+
let gen_chunk = client.fetch_generation(&gen_id)?;
debug!("gen: {:?}", gen_chunk);
diff --git a/src/generation.rs b/src/generation.rs
index dc9bf0c..5d04a9f 100644
--- a/src/generation.rs
+++ b/src/generation.rs
@@ -158,6 +158,7 @@ mod test {
/// A finished generation.
///
/// A generation is finished when it's on the server. It can be restored.
+#[derive(Debug, Clone)]
pub struct FinishedGeneration {
id: ChunkId,
ended: String,
diff --git a/src/lib.rs b/src/lib.rs
index 995cdeb..a06d396 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,9 +6,11 @@ pub mod chunkid;
pub mod chunkmeta;
pub mod client;
pub mod cmd;
+pub mod error;
pub mod fsentry;
pub mod fsiter;
pub mod generation;
+pub mod genlist;
pub mod index;
pub mod indexedstore;
pub mod server;
diff --git a/subplot/client.py b/subplot/client.py
index 1dcbe8c..0a09d31 100644
--- a/subplot/client.py
+++ b/subplot/client.py
@@ -24,9 +24,17 @@ def configure_client(ctx, filename=None):
def run_obnam_restore(ctx, filename=None, genid=None, todir=None):
+ genid = ctx["vars"][genid]
+ run_obnam_restore_with_genref(ctx, filename=filename, genref=genid, todir=todir)
+
+
+def run_obnam_restore_latest(ctx, filename=None, todir=None):
+ run_obnam_restore_with_genref(ctx, filename=filename, genref="latest", todir=todir)
+
+
+def run_obnam_restore_with_genref(ctx, filename=None, genref=None, todir=None):
runcmd_run = globals()["runcmd_run"]
- genid = ctx["vars"][genid]
runcmd_run(
ctx,
[
@@ -36,7 +44,7 @@ def run_obnam_restore(ctx, filename=None, genid=None, todir=None):
"--config",
filename,
"restore",
- genid,
+ genref,
todir,
],
)
diff --git a/subplot/client.yaml b/subplot/client.yaml
index f8e89b6..e526304 100644
--- a/subplot/client.yaml
+++ b/subplot/client.yaml
@@ -7,6 +7,9 @@
- when: "I invoke obnam --config {filename} restore <{genid}> {todir}"
function: run_obnam_restore
+- when: "I invoke obnam --config {filename} restore latest {todir}"
+ function: run_obnam_restore_latest
+
- then: "backup generation is {varname}"
function: capture_generation_id