src/bin/proxmox-backup-client.rs: generate a log file
This commit is contained in:
parent
3b151414f8
commit
17d6979afd
@ -3,8 +3,10 @@ extern crate proxmox_backup;
|
|||||||
use failure::*;
|
use failure::*;
|
||||||
//use std::os::unix::io::AsRawFd;
|
//use std::os::unix::io::AsRawFd;
|
||||||
use chrono::{DateTime, Local, Utc, TimeZone};
|
use chrono::{DateTime, Local, Utc, TimeZone};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use proxmox_backup::tools;
|
use proxmox_backup::tools;
|
||||||
|
use proxmox_backup::flog;
|
||||||
use proxmox_backup::cli::*;
|
use proxmox_backup::cli::*;
|
||||||
use proxmox_backup::api_schema::*;
|
use proxmox_backup::api_schema::*;
|
||||||
use proxmox_backup::api_schema::router::*;
|
use proxmox_backup::api_schema::router::*;
|
||||||
@ -26,10 +28,10 @@ lazy_static! {
|
|||||||
static ref BACKUPSPEC_REGEX: Regex = Regex::new(r"^([a-zA-Z0-9_-]+):(.+)$").unwrap();
|
static ref BACKUPSPEC_REGEX: Regex = Regex::new(r"^([a-zA-Z0-9_-]+):(.+)$").unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn backup_directory(
|
fn backup_directory<P: AsRef<Path>>(
|
||||||
client: &mut HttpClient,
|
client: &mut HttpClient,
|
||||||
repo: &BackupRepository,
|
repo: &BackupRepository,
|
||||||
body: Body,
|
dir_path: P,
|
||||||
archive_name: &str,
|
archive_name: &str,
|
||||||
backup_time: DateTime<Utc>,
|
backup_time: DateTime<Utc>,
|
||||||
chunk_size: Option<u64>,
|
chunk_size: Option<u64>,
|
||||||
@ -51,6 +53,10 @@ fn backup_directory(
|
|||||||
|
|
||||||
let path = format!("api2/json/admin/datastore/{}/catar?{}", repo.store, query);
|
let path = format!("api2/json/admin/datastore/{}/catar?{}", repo.store, query);
|
||||||
|
|
||||||
|
let stream = CaTarBackupStream::open(dir_path.as_ref())?;
|
||||||
|
|
||||||
|
let body = Body::wrap_stream(stream);
|
||||||
|
|
||||||
client.upload("application/x-proxmox-backup-catar", body, &path)?;
|
client.upload("application/x-proxmox-backup-catar", body, &path)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -202,16 +208,24 @@ fn create_backup(
|
|||||||
|
|
||||||
client.login()?; // login before starting backup
|
client.login()?; // login before starting backup
|
||||||
|
|
||||||
|
let log_file_name = format!("backup-log-{}.log", backup_time.format("%Y-%m-%dT%H:%M:%S"));
|
||||||
|
|
||||||
|
let mut log = tools::FileLogger::new(&log_file_name, true)?;
|
||||||
|
|
||||||
|
flog!(log, "Starting backup");
|
||||||
|
flog!(log, "Client name: {}", tools::nodename());
|
||||||
|
flog!(log, "UTC Start Time: {}", Utc::now().format("%c"));
|
||||||
|
|
||||||
for (filename, target) in upload_list {
|
for (filename, target) in upload_list {
|
||||||
println!("Upload '{}' to '{:?}'", filename, repo);
|
flog!(log, "Upload '{}' to '{:?}' as {}", filename, repo, target);
|
||||||
|
backup_directory(&mut client, &repo, &filename, &target, backup_time, chunk_size_opt)?;
|
||||||
let stream = CaTarBackupStream::open(&filename)?;
|
|
||||||
|
|
||||||
let body = Body::wrap_stream(stream);
|
|
||||||
|
|
||||||
backup_directory(&mut client, &repo, body, &target, backup_time, chunk_size_opt)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flog!(log, "Upload backup log");
|
||||||
|
// fixme: impl upload log
|
||||||
|
|
||||||
|
flog!(log, "UTC End Time: {}", Utc::now().format("%c"));
|
||||||
|
|
||||||
//datastore.garbage_collection()?;
|
//datastore.garbage_collection()?;
|
||||||
|
|
||||||
Ok(Value::Null)
|
Ok(Value::Null)
|
||||||
|
@ -2,7 +2,7 @@ use failure::*;
|
|||||||
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::os::unix::io::FromRawFd;
|
use std::os::unix::io::FromRawFd;
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use futures::{Async, Poll};
|
use futures::{Async, Poll};
|
||||||
use futures::stream::Stream;
|
use futures::stream::Stream;
|
||||||
@ -54,7 +54,7 @@ impl CaTarBackupStream {
|
|||||||
Ok(Self { pipe: Some(pipe), buffer, child: Some(child) })
|
Ok(Self { pipe: Some(pipe), buffer, child: Some(child) })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open(dirname: &str) -> Result<Self, Error> {
|
pub fn open(dirname: &Path) -> Result<Self, Error> {
|
||||||
|
|
||||||
let dir = nix::dir::Dir::open(dirname, OFlag::O_DIRECTORY, Mode::empty())?;
|
let dir = nix::dir::Dir::open(dirname, OFlag::O_DIRECTORY, Mode::empty())?;
|
||||||
let path = std::path::PathBuf::from(dirname);
|
let path = std::path::PathBuf::from(dirname);
|
||||||
|
Loading…
Reference in New Issue
Block a user