Files
x3-backup/src/rsync_manager.h
T
x3 f95a634655 feat: add backup progress estimation with time remaining
- Add estimate_backup_size() using du -sb before rsync starts
- Parse transfer speed from rsync output (KB/s, MB/s, GB/s)
- Calculate remaining time based on speed and remaining bytes
- Show estimated time remaining and size progress in UI
- Add format_time_remaining() for human-readable time display
- New UI elements: backup_time_label_ and backup_size_label_
2026-09-07 19:29:29 +00:00

66 lines
1.8 KiB
C++

#pragma once
#include <string>
#include <vector>
#include <functional>
#include <atomic>
#include <thread>
#include <mutex>
#include <chrono>
#include "config.h"
struct RsyncProgress {
int64_t files_transferred = 0;
int64_t files_total = 0;
int64_t bytes_transferred = 0;
int64_t bytes_total = 0;
int speed = 0;
int64_t estimated_total_size = 0;
double elapsed_seconds = 0;
double estimated_remaining = 0;
std::string current_file;
std::string log_line;
bool finished = false;
bool error = false;
std::string error_message;
};
class RsyncManager {
public:
RsyncManager(Config& config);
bool create_snapshot(const std::string& snapshot_name,
const std::string& source,
const std::string& dest,
const std::string& link_dest = "");
bool restore_files(const std::string& snapshot_path,
const std::vector<std::string>& files,
const std::string& restore_dest,
const std::string& sudo_password);
bool restore_full_snapshot(const std::string& snapshot_path,
const std::string& restore_dest,
const std::string& sudo_password);
void cancel();
bool is_running() const { return running_; }
std::function<void(const RsyncProgress&)> on_progress;
int64_t estimate_backup_size(const std::string& source);
std::string format_time_remaining(double seconds);
private:
Config& config_;
std::atomic<bool> running_{false};
std::atomic<bool> cancel_requested_{false};
std::thread worker_;
std::mutex log_mutex_;
std::vector<std::string> log_buffer_;
std::chrono::steady_clock::time_point start_time_;
std::vector<std::string> build_exclude_args();
bool run_rsync(const std::vector<std::string>& args);
void parse_progress_line(const std::string& line, RsyncProgress& prog);
};