From deda0b7ce7640835016b73512ee0c88e9f7f2059 Mon Sep 17 00:00:00 2001 From: Roland Date: Thu, 19 Nov 2026 16:55:29 -0700 Subject: [PATCH] Sync and Backup: a secondary WROLPi, and the backup drive's trash - New page, Sync: making a WROLPi a secondary of a primary, what is and is not copied, the sync window, what happens during a sync, the trash and the delete delay, excluded folders, WROL Mode, Docker, and the messages a refused sync shows. - Backup is rewritten around the backup drive (it taught a hand-made rsync job over SSH): setting it up, its window, what is copied, the trash and its delete delay, and replacing a failed media drive. - How Configs Work lists sync.yaml and sync_state.yaml. Co-Authored-By: Claude Opus 5.5 --- docs/index.md | 1 + docs/system/backup.md | 115 ++++++++++++++++++++++++--------------- docs/system/configs.md | 2 + docs/system/sync.md | 119 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 193 insertions(+), 44 deletions(-) create mode 100644 docs/system/sync.md diff --git a/docs/index.md b/docs/index.md index 552ac59..d5148d3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -17,6 +17,7 @@ Information about a WROLPi system. * [Collections](system/collections/index.md) * [Reorganize Collections](system/collections/reorganization.md) * [Backup](system/backup.md) +* [Sync: a Second WROLPi](system/sync.md) * [Logs](system/logs.md) * [Systems](system/index.md) * [Services (systemd)](system/systemd.md) diff --git a/docs/system/backup.md b/docs/system/backup.md index 6da6ea1..5f5c48c 100644 --- a/docs/system/backup.md +++ b/docs/system/backup.md @@ -1,55 +1,82 @@ # Backup -## Backup from one WROLPi to another +WROLPi can keep two kinds of copies of your library: -As of the writing of this tutorial, WROLPi does not have an official way to back up a WROLPi. The current workaround -is to use rsync with a manual refresh. +| Copy | Where | Use it for | +|---|---|---| +| A **backup drive** | A second drive plugged into the same WROLPi | Replacing the media drive if it fails | +| A **secondary WROLPi** | Another WROLPi on your network | A second, usable library somewhere else. See [Sync](sync.md). | -Follow these steps to automate backup of your WROLPi. +They can be combined: a secondary can have a backup drive of its own. -1. SSH/login to the primary WROLPi, add a password for the "wrolpi" user - - `sudo -u wrolpi passwd` -2. SSH/login into the backup WROLPi - 1. Switch to the "wrolpi" user: - - `sudo su - wrolpi` - 2. Generate SSH keys for the wrolpi user: - - `ssh-keygen` - 3. Copy ssh keys to the primary WROLPi (using the password from step 1) - - `ssh-copy-id wrolpi@PRIMARY_IP_ADDRESS` - 4. Ensure the backup can login to the primary by ssh'ing into it from the backup - - `ssh wrolpi@PRIMARY_IP_ADDRESS` - 5. Copy all files from the primary to the backup - - `rsync -avrle ssh wrolpi@PRIMARY_IP_ADDRESS:/media/wrolpi/* /media/wrolpi` +## Backup Drive -Files are now synchronized, now you need to automate it. Copy/paste the following into the shell of the backup WROLPi, -it will create a bash script that will copy files from the primary to the backup WROLPi. +A backup drive mirrors your media directory, so if the media drive fails, the backup drive can take its place and +WROLPi starts from it with your files, configs and database. -```shell -cat > /home/wrolpi/backup_wrolpi.sh << 'EOF' -#! /usr/bin/env bash -logfile=/home/wrolpi/wrolpi.log +> Plug in and mount a second drive (see [External USB Drives](external-drives.md)). Click **Admin**, then **Sync**. +> Under **Backup Drive**, choose the drive, and click **Save**. -echo >> ${logfile} -echo >> ${logfile} -echo start $(date +"%Y-%m-%d %H:%M:%S") >> ${logfile} -/usr/bin/rsync \ - --exclude="lost+found" \ - --exclude="tags" \ - -avue ssh \ - wrolpi@PRIMARY_IP_ADDRESS:/media/wrolpi/* \ - /media/wrolpi/ \ - 2>&1 >> ${logfile} -echo end $(date +"%Y-%m-%d %H:%M:%S") >> ${logfile} +To back up into a folder on the drive rather than the whole drive, enter it under **Folder on the drive**. Click +**Back Up Now** to make the first copy; it copies the whole library, so it can take many hours. -EOF -``` +Backup drives are not available when WROLPi runs in Docker, which cannot reach other drives. Use a +[secondary WROLPi](sync.md) instead. -1. Modify the above file (at `/home/wrolpi/backup_wrolpi.sh`), replacing `PRIMARY_IP_ADDRESS` with the correct IP - address. -2. Modify the crontab of the "wrolpi" user so this script runs daily - - `sudo -u wrolpi crontab -e` -3. Add the following cron entry to run the backup script +### When a Backup Runs -```shell -0 4 * * * /bin/bash -l /home/wrolpi/backup_wrolpi.sh -``` +A backup runs when you click **Back Up Now**, or by itself within a daily window: + +> Under **Backup Drive**, set **Backup Window Start** and **Backup Window End** and click **Save**. + +Within the window the backup drive is updated every hour. Leave both times empty to back up only with **Back Up +Now**. WROLPi stays usable while it backs up. **Stop Backup** stops a backup, except while the database is being +copied, which runs to the end. + +A backup is only written when the drive you chose is mounted where you chose it. An unplugged drive leaves an empty +folder behind, and WROLPi never fills the system drive with it. + +### What Is Copied + +Everything in the media directory, except: + +| Not copied | Why | +|---|---| +| `tags` and the playlists directory | Hard links that WROLPi rebuilds when it starts. | +| Folders you exclude | See below. | + +The database is not copied as a file, which could be caught half-written, but as a consistent snapshot, written +only when it changed since the last backup. + +### Files Deleted Here + +A file you delete from WROLPi, or the old version of a file that changes, is not deleted from the backup drive at +once. It is moved to a trash folder on the backup drive, `.backup-trash`, in a folder for the day, and removed after +**30 days**: + +> Under **Backup Drive**, change **Files deleted here: Delete after N days**, or check **Never delete them**, and +> click **Save**. + +The oldest trash is removed sooner if the backup drive is nearly full. A file you deleted by mistake can be copied +back from `.backup-trash` within those days. + +> **Warning!** The first backup after upgrading to this version moves every file the media directory no longer has +> into the trash, including any files of your own on the backup drive that are not in the media directory. Keep +> other files off the backup drive, or back up into a folder of their own. + +A backup is refused when the media directory is not mounted, or holds no WROLPi library: copied with deletes, an +empty media directory would move the whole backup drive into the trash. + +### Excluding Folders + +> Under **Backup Drive**, click **Choose Folders**, check the folders not to back up, click **Done**, then +> **Save**. + +Files already on the backup drive in an excluded folder are kept; delete them yourself to free space. + +### Replacing the Media Drive + +If the media drive fails, mount the backup drive at `/media/wrolpi` in its place (see +[External USB Drives](external-drives.md)) and start WROLPi. If you backed up into a folder on the drive, copy +that folder's contents to a new media drive instead. Files in `.backup-trash` are hidden from WROLPi; delete the +folder once you no longer need them. diff --git a/docs/system/configs.md b/docs/system/configs.md index 5e3b58d..77f7a3d 100644 --- a/docs/system/configs.md +++ b/docs/system/configs.md @@ -27,6 +27,8 @@ All configs are stored in the `config` directory of your media directory: `/medi | `download_cache.yaml` | Cached video durations (safe to ignore). | | `map_pins.yaml` | Your [Map](../modules/map/index.md) pins. | | `maps.yaml` | The [Map](../modules/map/index.md) files the map ignores (the Visible toggle on the Map's Manage tab). | +| `sync.yaml` | This WROLPi's [Sync](sync.md) role, its primary, its sync window, and its [Backup](backup.md) drive. Never copied to a secondary. | +| `sync_state.yaml` | When the last [Sync](sync.md) ran and what it did. Written by the Controller. | | `bookmarks.yaml` | Your [Bookmarks](../modules/bookmarks/index.md), including their directories and order. | | `recently_viewed.yaml` | Your 1,000 most recently viewed files, and [where you left off](viewing-progress.md) in each. | | `inventory/*.yaml` | One file per [Inventory](../modules/inventory/index.md), plus the food catalog. | diff --git a/docs/system/sync.md b/docs/system/sync.md new file mode 100644 index 0000000..e59d925 --- /dev/null +++ b/docs/system/sync.md @@ -0,0 +1,119 @@ +# Sync: a Second WROLPi + +A **secondary** WROLPi keeps an exact copy of a **primary** WROLPi's library: every file in its media directory (maps +and repositories too), its database, and its Tags, Channels, Domains, Playlists, Downloads and other settings. Use it +for a second copy of your library in another room, another building, or another vehicle. + +Every WROLPi is a primary unless you make it a secondary. A primary needs no setup: it is ready to be copied. + +> **Warning!** A secondary is overwritten. Every sync replaces its library and database with the primary's, so +> anything you change on a secondary is lost at the next sync. Use the primary for downloading, tagging and +> organizing; use the secondary for reading and watching. + +## Before You Start + +| Requirement | Why | +|---|---| +| Both WROLPis run the **same version** of WROLPi | The secondary takes the primary's database, which must match its own code. A sync is refused otherwise: upgrade both. | +| The secondary can reach the primary on the network | It reads the primary's web address, and copies files from port **8873** (rsync). | +| The primary's media drive is mounted | An unmounted drive looks like an empty library, so a sync from it is refused. | +| The secondary's drive is as large as the primary's library | Everything is copied, unless you exclude folders (below). | + +## Make a WROLPi a Secondary + +> On the WROLPi that will be the copy, click **Admin**, then **Sync**. Choose **Secondary** under "This WROLPi +> is", enter the primary's address (for example `https://192.168.0.10`), and click **Save**. + +Click **Test Connection** to check that the secondary can reach the primary. Then click **Sync Now** to make the +first copy. The first sync copies the whole library, so it can take many hours; later syncs only copy what changed. + +From then on, the secondary shows a "Secondary WROLPi" warning on its pages, and it never downloads anything: the +primary does that. + +## When a Sync Runs + +A sync runs when you click **Sync Now**, or by itself within a daily window: + +> On the Sync page, set **Sync Window Start** and **Sync Window End** (for example 01:00 and 05:00) and click +> **Save**. + +Within the window the secondary syncs again 15 minutes after the last sync finished. Leave both times empty to sync +only with **Sync Now**. The window is in WROLPi's timezone (set in **Admin**, **Settings**). + +## During a Sync + +The secondary is unavailable while it syncs: WROLPi stops its own server so that nothing changes while its library +is replaced. WROLPi shows the sync's progress over every page, with a **Stop Sync** button, and so does the +Controller's page (the secondary's address on port 80, or 8080 in Docker). When the sync finishes, WROLPi starts +again. + +A sync in which nothing changed is short: under a minute on a small library, a few minutes on a very large one, +mostly spent comparing files. + +A sync is stopped, and WROLPi is started again, if you click **Stop Sync** or if the primary stops answering for +five minutes. A file that was being copied is finished at the next sync. + +You get a notification when a sync copied or moved files, or failed. A sync that changed nothing, or that you +stopped, is not announced. + +## What Is Copied + +Everything in the primary's media directory, including folders the primary +[ignores](../modules/files/index.md#files-tools), and the primary's database. These stay the secondary's own: + +| Not copied | Why | +|---|---| +| `wrolpi.yaml` | This WROLPi's own settings (hotspot, timezone, WROL Mode). The settings that describe the library, such as where videos and maps are kept and which directories are ignored, are taken from the primary. | +| `sync.yaml` | This WROLPi's role, its primary, and its sync window. | +| `controller.yaml`, `fstab.yaml`, `smb.conf` | This machine's drives, shares and services. | +| `config/ssl` | This WROLPi's HTTPS certificates. | +| Cookies | Downloader logins are never copied. | +| `config/backup` | This WROLPi's own config backups. | +| `tags` and the playlists directory | Hard links that WROLPi rebuilds when it starts. | + +## Files the Primary Deletes + +A file the primary deletes, or the old version of a file it changes, is not deleted from the secondary at once. It +is moved to a trash folder, `.sync-trash`, in a folder for the day, and removed after **30 days**: + +> On the Sync page, change **Files the primary deletes: Delete after N days**, or check **Never delete them**, and +> click **Save**. + +The oldest trash is removed sooner if the secondary's drive is nearly full. To bring a file back, copy it from +`.sync-trash` to the **primary**: restored only on the secondary, it would be moved to the trash again at the next +sync. + +## Excluding Folders + +To keep a folder of the primary off a smaller secondary: + +> On the Sync page, click **Choose Folders**, check the folders not to copy, click **Done**, then **Save**. + +Files already copied into an excluded folder are kept; delete them yourself to free space. Because the secondary's +database is the primary's, the files of an excluded folder are still listed on the secondary, but they do not open. + +## WROL Mode + +Enabling WROL Mode on a secondary stops syncing: a WROLPi in WROL Mode is in use and must not +change under its users. The "Secondary WROLPi" warning is hidden while WROL Mode is enabled. Disable WROL Mode to +sync again. + +## Docker + +A WROLPi running in Docker can be a primary or a secondary. Its Controller runs the copy in a short-lived +container made from the API's container, so the media directory only needs to be set on the `api` service. The +primary serves its library from a container named `wrolpi-rsyncd-1`, on port 8873. + +## Troubleshooting + +| Message | What to do | +|---|---| +| "The primary's WROLPi version ... is not this WROLPi's" | Upgrade both WROLPis to the same version. | +| "The primary's database migration ... is not this WROLPi's" | The same: upgrade both. | +| "The primary's media directory is not mounted" | Mount the primary's media drive. | +| "The primary's media directory ... is not this WROLPi's" | Both must use the same media directory path, as their databases name files by their full path. | +| "The primary address is not a primary WROLPi" | The address points at another secondary, or at this WROLPi. | +| rsync failed, or the primary did not answer | Check that the secondary can reach the primary's port 8873, and that the primary is running. | +| "Not enough free space for the primary's database" | Free space on the secondary, or wait for its trash to be removed. | + +A secondary can also keep a [Backup Drive](backup.md) of its own.