tape: use SnapshotReader to create snapshot archive
This commit is contained in:
parent
d108b610fd
commit
b9ee86efe1
@ -25,6 +25,7 @@ use crate::{
|
|||||||
///
|
///
|
||||||
/// This make it easy to iterate over all used chunks and files.
|
/// This make it easy to iterate over all used chunks and files.
|
||||||
pub struct SnapshotReader {
|
pub struct SnapshotReader {
|
||||||
|
snapshot: BackupDir,
|
||||||
file_list: Vec<String>,
|
file_list: Vec<String>,
|
||||||
locked_dir: Dir,
|
locked_dir: Dir,
|
||||||
}
|
}
|
||||||
@ -59,7 +60,12 @@ impl SnapshotReader {
|
|||||||
file_list.push(CLIENT_LOG_BLOB_NAME.to_string());
|
file_list.push(CLIENT_LOG_BLOB_NAME.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self { file_list, locked_dir })
|
Ok(Self { snapshot, file_list, locked_dir })
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the snapshot directory
|
||||||
|
pub fn snapshot(&self) -> &BackupDir {
|
||||||
|
&self.snapshot
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the list of files the snapshot refers to.
|
/// Returns the list of files the snapshot refers to.
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use std::path::{Path, PathBuf};
|
|
||||||
|
|
||||||
use proxmox::{
|
use proxmox::{
|
||||||
sys::error::SysError,
|
sys::error::SysError,
|
||||||
@ -10,6 +9,7 @@ use proxmox::{
|
|||||||
|
|
||||||
use crate::tape::{
|
use crate::tape::{
|
||||||
TapeWrite,
|
TapeWrite,
|
||||||
|
SnapshotReader,
|
||||||
file_formats::{
|
file_formats::{
|
||||||
PROXMOX_TAPE_BLOCK_SIZE,
|
PROXMOX_TAPE_BLOCK_SIZE,
|
||||||
PROXMOX_BACKUP_SNAPSHOT_ARCHIVE_MAGIC_1_0,
|
PROXMOX_BACKUP_SNAPSHOT_ARCHIVE_MAGIC_1_0,
|
||||||
@ -27,11 +27,12 @@ use crate::tape::{
|
|||||||
/// backup task must rewrite the whole file on the next media).
|
/// backup task must rewrite the whole file on the next media).
|
||||||
pub fn tape_write_snapshot_archive<'a>(
|
pub fn tape_write_snapshot_archive<'a>(
|
||||||
writer: &mut (dyn TapeWrite + 'a),
|
writer: &mut (dyn TapeWrite + 'a),
|
||||||
snapshot: &str,
|
snapshot_reader: &SnapshotReader,
|
||||||
base_path: &Path,
|
|
||||||
file_list: &[String],
|
|
||||||
) -> Result<Option<Uuid>, std::io::Error> {
|
) -> Result<Option<Uuid>, std::io::Error> {
|
||||||
|
|
||||||
|
let snapshot = snapshot_reader.snapshot().to_string();
|
||||||
|
let file_list = snapshot_reader.file_list();
|
||||||
|
|
||||||
let header_data = snapshot.as_bytes().to_vec();
|
let header_data = snapshot.as_bytes().to_vec();
|
||||||
|
|
||||||
let header = MediaContentHeader::new(
|
let header = MediaContentHeader::new(
|
||||||
@ -52,17 +53,16 @@ pub fn tape_write_snapshot_archive<'a>(
|
|||||||
let mut encoder = pxar::encoder::sync::Encoder::new(PxarTapeWriter::new(writer), &root_metadata)?;
|
let mut encoder = pxar::encoder::sync::Encoder::new(PxarTapeWriter::new(writer), &root_metadata)?;
|
||||||
|
|
||||||
for filename in file_list.iter() {
|
for filename in file_list.iter() {
|
||||||
let mut path = PathBuf::from(base_path);
|
|
||||||
path.push(filename);
|
|
||||||
|
|
||||||
let mut file = std::fs::File::open(&path)?;
|
let mut file = snapshot_reader.open_file(filename)
|
||||||
|
.map_err(|err| proxmox::io_format_err!("open file '{}' failed - {}", filename, err))?;
|
||||||
let metadata = file.metadata()?;
|
let metadata = file.metadata()?;
|
||||||
let file_size = metadata.len();
|
let file_size = metadata.len();
|
||||||
|
|
||||||
let metadata: pxar::Metadata = metadata.into();
|
let metadata: pxar::Metadata = metadata.into();
|
||||||
|
|
||||||
if !metadata.is_regular_file() {
|
if !metadata.is_regular_file() {
|
||||||
proxmox::io_bail!("path {:?} is not a regular file", path);
|
proxmox::io_bail!("file '{}' is not a regular file", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut remaining = file_size;
|
let mut remaining = file_size;
|
||||||
@ -70,14 +70,14 @@ pub fn tape_write_snapshot_archive<'a>(
|
|||||||
while remaining != 0 {
|
while remaining != 0 {
|
||||||
let got = file.read(&mut file_copy_buffer[..])?;
|
let got = file.read(&mut file_copy_buffer[..])?;
|
||||||
if got as u64 > remaining {
|
if got as u64 > remaining {
|
||||||
proxmox::io_bail!("file {:?} changed while reading", path);
|
proxmox::io_bail!("file '{}' changed while reading", filename);
|
||||||
}
|
}
|
||||||
out.write_all(&file_copy_buffer[..got])?;
|
out.write_all(&file_copy_buffer[..got])?;
|
||||||
remaining -= got as u64;
|
remaining -= got as u64;
|
||||||
|
|
||||||
}
|
}
|
||||||
if remaining > 0 {
|
if remaining > 0 {
|
||||||
proxmox::io_bail!("file {:?} shrunk while reading", path);
|
proxmox::io_bail!("file '{}' shrunk while reading", filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
encoder.finish()?;
|
encoder.finish()?;
|
||||||
|
Loading…
Reference in New Issue
Block a user