DEV Community

amekusa03
amekusa03

Posted on

Building GXBackup: A Smart, Load-Aware Linux Backup Utility in C++17 and Qt 6

πŸš€ Building GXBackup: A Smart, Load-Aware Linux Backup Utility in C++17 and Qt 6

When working on Linux desktops or development workstations, backups are essential. However, many existing GUI backup utilities suffer from common drawbacks:

  • They are heavy Electron wrappers that consume hundreds of megabytes of RAM.
  • They hog system resources during background backup tasks, causing stuttering while compiling code or rendering assets.
  • They lack granular control over resource usage and desktop integration.

To solve this, I created GXBackup β€” a fast, lightweight, native C++17 and Qt 6/Qt 5 application for Linux. It combines the bulletproof reliability of rsync with a modern UI, system tray integration, and smart CPU/load-aware auto-pausing.

Here is an overview of how GXBackup works, its key features, and some of the technical design decisions behind it.


🌟 Key Features at a Glance

  • πŸ“Έ Time Machine Style Snapshots: Uses rsync's --link-dest option to create incremental point-in-time snapshots using hardlinks, saving significant disk space.
  • ⚑ Smart Load Throttling: Monitors /proc/stat and /proc/loadavg in real time. If CPU usage or load average exceeds configured thresholds, GXBackup automatically pauses the backup job and resumes it once the system cools down.
  • ⏰ Automated Scheduling & Catch-Up: Set daily or weekly backup schedules. If your machine was powered off during a scheduled run, GXBackup detects the missed run at boot and executes a "catch-up" backup automatically.
  • πŸ”” System Tray & Desktop Integration: Operates quietly in the background with minimal memory footprint and native notification support.
  • 🌐 Dynamic Runtime i18n: Ships in English by default with dynamic runtime language switching (e.g., Japanese/English) without requiring an app restart.

πŸ›  Tech Stack & Architecture

  • Language: C++17
  • Framework: Qt 6 / Qt 5 (Core, Gui, Widgets, Concurrent)
  • Backend Engine: rsync
  • Build System: CMake (3.16+)

Project Structure

GXBackup/
β”œβ”€β”€ CMakeLists.txt         # Build configuration
β”œβ”€β”€ resources/             # Icons & embedded Qt resources (.qrc)
β”œβ”€β”€ translations/          # Translation files (.ts / .qm)
└── src/
    β”œβ”€β”€ main.cpp           # Entry point & CLI argument parsing
    β”œβ”€β”€ core/              # Core logic & backend
    β”‚   β”œβ”€β”€ AutostartManager.cpp  # XDG desktop autostart manager
    β”‚   β”œβ”€β”€ BackupController.cpp  # Backup workflow coordinator
    β”‚   β”œβ”€β”€ HistoryManager.cpp   # Execution history persistence
    β”‚   β”œβ”€β”€ LanguageManager.cpp  # Dynamic i18n & QTranslator manager
    β”‚   β”œβ”€β”€ ProfileManager.cpp   # Profile configuration (JSON)
    β”‚   β”œβ”€β”€ RsyncProcess.cpp     # rsync process lifecycle & progress parser
    β”‚   β”œβ”€β”€ ScheduleManager.cpp  # Cron-like timer & missed run detector
    β”‚   └── SystemMonitor.cpp    # Real-time /proc resource reader
    └── ui/                # Qt GUI & dialogs
        β”œβ”€β”€ HistoryDialog.cpp    # History table view
        β”œβ”€β”€ LogViewer.cpp        # Console log output window
        β”œβ”€β”€ MainWindow.cpp       # Main dashboard & tray icon
        └── ProfileDialog.cpp    # Profile configuration editor
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Deep-Dive: What Makes GXBackup Unique?

1. Smart Resource Throttling (SystemMonitor)

One of the biggest pain points of background backups on developer machines is resource contention. If rsync starts indexing thousands of files while you are running cmake --build or docker build, your PC can lock up.

GXBackup addresses this by inspecting system metrics directly from /proc:

// Reading CPU & Load Average from Linux pseudo-filesystems
void SystemMonitor::checkMetrics()
{
    double cpuUsage = readCpuUsagePercent();
    double loadAvg = readLoadAverage1Min();

    emit metricsUpdated(cpuUsage, loadAvg);

    bool highLoad = (cpuUsage >= m_cpuThreshold) || (loadAvg >= m_loadAvgThreshold);
    if (highLoad != m_isHighLoadState) {
        m_isHighLoadState = highLoad;
        emit loadStateChanged(m_isHighLoadState);
    }
}
Enter fullscreen mode Exit fullscreen mode

When high load is detected, BackupController intercepts the event and signals RsyncProcess to pause execution, ensuring your desktop stays responsive.

2. Native rsync Execution & Real-Time Progress Parsing

Rather than wrapping rsync blindly, GXBackup launches rsync asynchronously via QProcess and parses its output stream (--progress format) in real time to calculate:

  • Transfer percentage
  • Current transfer speed (MB/s)
  • Transferred data size
  • Estimated time remaining (ETA)
void RsyncProcess::parseProgress(const QString &line)
{
    // Regular expression parsing of rsync --progress output lines:
    // "  1,234,567  45%  12.34MB/s  0:00:15"
    static QRegularExpression re(R"(\s*([\d,]+)\s+(\d+)%\s+([\d\.]+\w+/s)\s+([\d:]+))");
    QRegularExpressionMatch match = re.match(line);

    if (match.hasMatch()) {
        int percent = match.captured(2).toInt();
        QString speed = match.captured(3);
        QString transferred = formatBytes(match.captured(1).remove(',').toULongLong());
        QString eta = match.captured(4);

        emit progressUpdated(percent, speed, transferred, eta);
    }
}
Enter fullscreen mode Exit fullscreen mode

3. Dynamic i18n & Instant Language Switcher

In Qt applications, switching languages usually requires restarting the app. GXBackup uses a custom LanguageManager singleton that loads .qm binary translation files from Qt's resource system (:/translations/gxbackup_ja.qm) and broadcasts dynamic QEvent::LanguageChange events.

All UI windows override changeEvent:

void MainWindow::changeEvent(QEvent *event)
{
    if (event->type() == QEvent::LanguageChange) {
        retranslateUi();
    }
    QMainWindow::changeEvent(event);
}
Enter fullscreen mode Exit fullscreen mode

This allows users to switch between English and Japanese on the fly from the Settings -> Language menu with zero restart downtime!


πŸ’» Getting Started

Prerequisites

For Ubuntu / Debian:

sudo apt update
sudo apt install build-essential cmake qt6-base-dev rsync
Enter fullscreen mode Exit fullscreen mode

Build & Run

# Clone repository
git clone https://github.com/amekusa03/GXBackup.git
cd GXBackup

# Build project
mkdir build && cd build
cmake ..
make -j$(nproc)

# Run GUI
./GXBackup
Enter fullscreen mode Exit fullscreen mode

πŸ‘₯ Open Source & Feedback

GXBackup is open source under the MIT License.

If you are looking for a fast, responsive backup tool for your Linux desktop or home server, give GXBackup a try!


Tags: #linux #cpp #qt #opensource

Top comments (0)