proxmox-backup-proxy: add task archive rotation
this starts a task once a day at "00:00" that rotates the task log archive if it is bigger than 500k if we want, we can make the schedule/size limit/etc. configurable, but for now it's ok to set fixed values for that Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
committed by
Dietmar Maurer
parent
c386b06fc6
commit
9a76091785
@ -1,5 +1,6 @@
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
use std::io::{Read, Write, BufRead, BufReader};
|
||||
use std::panic::UnwindSafe;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
@ -339,6 +340,27 @@ fn lock_task_list_files(exclusive: bool) -> Result<std::fs::File, Error> {
|
||||
Ok(lock)
|
||||
}
|
||||
|
||||
/// checks if the Task Archive is bigger that 'size_threshold' bytes, and
|
||||
/// rotates it if it is
|
||||
pub fn rotate_task_log_archive(size_threshold: u64, compress: bool, max_files: Option<usize>) -> Result<bool, Error> {
|
||||
let _lock = lock_task_list_files(true)?;
|
||||
let path = Path::new(PROXMOX_BACKUP_ARCHIVE_TASK_FN);
|
||||
let metadata = path.metadata()?;
|
||||
if metadata.len() > size_threshold {
|
||||
let mut logrotate = LogRotate::new(PROXMOX_BACKUP_ARCHIVE_TASK_FN, compress).ok_or_else(|| format_err!("could not get archive file names"))?;
|
||||
let backup_user = crate::backup::backup_user()?;
|
||||
logrotate.rotate(
|
||||
CreateOptions::new()
|
||||
.owner(backup_user.uid)
|
||||
.group(backup_user.gid),
|
||||
max_files,
|
||||
)?;
|
||||
Ok(true)
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
// atomically read/update the task list, update status of finished tasks
|
||||
// new_upid is added to the list when specified.
|
||||
fn update_active_workers(new_upid: Option<&UPID>) -> Result<(), Error> {
|
||||
|
Reference in New Issue
Block a user