]>
git.proxmox.com Git - proxmox-backup.git/blob - src/backup/datastore.rs
3 use std
::path
::{PathBuf, Path}
;
5 use crate::config
::datastore
;
6 use super::chunk_store
::*;
7 use super::image_index
::*;
10 chunk_store
: ChunkStore
,
15 pub fn open(store_name
: &str) -> Result
<Self, Error
> {
17 let config
= datastore
::config()?
;
18 let (_
, store_config
) = config
.sections
.get(store_name
)
19 .ok_or(format_err
!("no such datastore '{}'", store_name
))?
;
21 let path
= store_config
["path"].as_str().unwrap();
23 let chunk_store
= ChunkStore
::open(path
)?
;
26 chunk_store
: chunk_store
,
30 pub fn create_image_writer
<P
: AsRef
<Path
>>(&mut self, filename
: P
, size
: usize) -> Result
<ImageIndexWriter
, Error
> {
32 let index
= ImageIndexWriter
::create(&mut self.chunk_store
, filename
.as_ref(), size
)?
;
37 pub fn open_image_reader
<P
: AsRef
<Path
>>(&mut self, filename
: P
) -> Result
<ImageIndexReader
, Error
> {
39 let index
= ImageIndexReader
::open(&mut self.chunk_store
, filename
.as_ref())?
;
44 pub fn list_images(&self) -> Result
<Vec
<PathBuf
>, Error
> {
45 let base
= self.chunk_store
.base_path();
47 let mut list
= vec
![];
49 for entry
in std
::fs
::read_dir(base
)?
{
51 if entry
.file_type()?
.is_file() {
52 let path
= entry
.path();
53 if let Some(ext
) = path
.extension() {
64 fn sweep_used_chunks(&mut self) -> Result
<(), Error
> {
69 fn mark_used_chunks(&mut self) -> Result
<(), Error
> {
71 let image_list
= self.list_images()?
;
73 for path
in image_list
{
74 let mut index
= self.open_image_reader(path
)?
;
75 index
.mark_used_chunks();
81 pub fn garbage_collection(&mut self) -> Result
<(), Error
> {
83 self.mark_used_chunks()?
;
84 self.sweep_used_chunks()?
;