Home/Projects/RunBackup
Python 3rsyncRichLinuxIn daily use

RunBackup

Drive backups that refuse to destroy your backup.

RunBackup mirrors every source drive on a Linux server to its paired backup drive. It decides what to copy from real file changes, checks each pair for signs of trouble before writing anything, and keeps whatever it removes for 30 days. One command, run by hand or on a schedule.

Runs onLinux, as root
Copy enginersync
InterfaceLive terminal dashboard
ModesInteractive · autostart
How it worksScreensSafety guardsUsageConfigurationResults and exit codesBefore you run it

How a run works

Every run follows the same six steps, for every drive pair it finds.

Discover

Reads drives from lsblk and pairs each label with its _BK twin.

Fix permissions

Applies owner and ACL fixups to shared source folders.

Dry run

rsync counts real changes and deletions per pair.

Guard

Blocks any pair that looks empty, shrunk or delete-heavy.

Sync

Copies changes; removed files move to a dated holding folder.

Report

Prunes old holdings, writes the log and prints a summary.

On screen

A full-screen dashboard while it runs, then a summary that stays put when it finishes.

RunBackup live dashboard with four drive pairs, one syncing and one blocked.
Live dashboard: progress, transfer rate and an activity feed.
RunBackup interactive run asking about a blocked pair, followed by the run summary.
Interactive run: a blocked pair needs your answer before anything happens.

Example screens with sample drive names.

Safety guards

A drive that failed to mount looks exactly like a drive that was wiped. Mirroring either one would erase the backup, so RunBackup checks first.

Empty

Source looks empty

A source with almost nothing on it, paired with a full backup, is treated as a mount failure rather than a real change.

< 90%

Source has shrunk

If the source uses less than 90% of the space its backup uses, the pair is blocked until someone confirms it.

> 1,000

Too many deletions

A run that would delete more than 1,000 files from the backup is stopped before it starts.

In interactive mode you are asked about each blocked pair. In autostart mode the pair is skipped and the run exits with code 1, so a scheduler or monitor can flag it.

Usage

Run it interactively to watch and answer prompts, or add autostart for scheduled, hands-off runs.

# interactive
sudo python3 runbackup.py

# unattended, e.g. from cron or a timer
sudo python3 runbackup.py autostart

Requirements

  • Python 3 with the rich package
  • rsync and lsblk
  • ACL tools (setfacl) for permission fixups
  • Root access to read every file and preserve ownership
  • Labelled drives named LABEL and LABEL_BK

Configuration

All settings live in one block at the top of the script.

SettingDefaultWhat it does
BACKUP_SUFFIX"_BK"Suffix that marks a backup drive. A drive labelled MEDIA is paired with MEDIA_BK.
DELETED_DIR_NAME".rsync-deleted"Folder on each backup drive that receives deleted and overwritten files.
DELETED_RETENTION_DAYS30Days to keep those files before they are pruned.
SHRINK_GUARD_RATIO0.90Block a pair if the source uses less than this share of the backup’s used space.
MAX_DELETES1000Block a pair if one run would delete more files than this.
PRESERVE_ACLS_XATTRSTrueCopy POSIX ACLs and extended attributes. Needs ext4, xfs or btrfs on both sides; set False for NTFS or exFAT backups.
ENFORCE_OWNERSHIPFalseForce one owner, group and mode set on the backup copy instead of copying them faithfully.
ENFORCE_USER / GROUP / CHMODNone / "ServerOwner" / "D2775,F664"Used only when ownership is enforced. None means the user who ran sudo.
EXCLUDES["/lost+found/", "/.rsync-deleted/"]Paths never copied, and protected from deletion on the backup side.
PERMISSION_FIXUPSlist of foldersShared folders whose owner and ACLs are corrected on the source just before syncing, so the backup gets the same permissions in the same run.
LOG_DIR"/var/log/runbackup"Where each run’s log is written.
LOG_KEEP60How many past logs to keep.
LOG_FILE_NAMESTrueRecord every copied and deleted file name in the log.

Results

Each pair ends the run with one of these.

ResultMeaning
SyncedDry run found no changes, or the sync finished cleanly.
Synced (warnings)rsync returned code 24: some files vanished while copying. Usually harmless on a live drive.
Partialrsync returned code 23: some files could not be copied. Check the log for names.
BlockedA safety guard tripped. Interactive runs ask you; autostart skips the pair.
SkippedYou declined a blocked pair, or it was skipped in autostart.
Check failed / FailedThe dry run or the sync itself errored. Details are in the log.

Exit codes and logs

CodeMeaning
0Every pair synced or was already up to date.
1At least one pair failed, was blocked or was skipped.

Every run writes /var/log/runbackup/runbackup-<date_time>.log, listing each copied and deleted file. The 60 most recent logs are kept.

Before you run it

Large drives take a moment to check

The dry run reads every file’s details on every run, so the check phase can take a few minutes on big drives. In exchange it never misses a change.

The first run rewrites metadata

When moving from forced ownership to faithful copies, the first run updates owner and mode details across the whole backup. No file contents are recopied, but it takes a while.

Non-Linux backup drives

If a backup drive is NTFS or exFAT, set PRESERVE_ACLS_XATTRS = False, since those filesystems cannot hold Linux permissions.

Explore the other projects