- Assembly 51.8%
- Shell 16.4%
- C++ 12.7%
- PHP 7.6%
- Pascal 6.2%
- Other 5.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| debian | ||
| excludes | ||
| logrotate.d | ||
| systemd | ||
| usr_local_bin | ||
| default.inc | ||
| excludes-windows.inc | ||
| excludes.inc | ||
| README.md | ||
| rsnapshot-nightly-20261101-0936.tar.zst | ||
| rsnapshot-windows.conf | ||
| rsnapshot.conf | ||
rsnapshot Dual Backup: Linux Filesystems and Windows Filesystems via WSL
- What is rsnapshot?
- Notes
- Prerequisites
- Filesystem Structure
- Configuration
- Testing rsnapshot
- Scheduling (systemd)
- rsnapshot-report.sh
- Log files
- Invoking manually
- Excludes
Written and revised with Claude: chat session
This is a dual rsnapshot configuration. The two configurations are for:
-
Linux filesystems
- note: files in the WSL Linux filesystem should be transferred here
- for example:
/home,/etc,/usr/local, etc.
-
Windows filesystems
- for transferring Windows filesystem files via WSL
- for example, anything under
/mnt/c,/mnt/d, etc.
Both run every night from a single systemd timer, one after the other: Linux first, then Windows.
What is rsnapshot?
In case you don't know what rsnapshot is, it is a rotating incremental backup system. It performs daily backups, and every time a new backup is created it rotates the previous ones. The current day's backup is daily.0, the day before's is daily.1, and so on. At the end of a week the oldest daily becomes weekly.0. Every week these get rotated so you end up with weekly.1, weekly.2, etc. The same thing goes for months: monthly.0, monthly.1, monthly.2, etc.
I can't tell you how many times having backups has saved my skin. Operating information appliances always involves a certain level of risk that some important data or files may inadvertently become deleted.
It gives great peace of mind to know that you have not just a backup, but literally a series of daily backups going back a full week, and then weekly and monthly backups going back even further.
The backup storage is efficient because instead of creating completely new files on disk, for files that are unchanged from previous backups it creates hard links.
Restoration is as simple as copying files back into place.
I chose rsnapshot because it is solid and tested, and based on purely free and Open-Source technologies, which every good tool should be.
Notes
- My backup filesystem is BTRFS and is mounted under
/mnt/lbackon my backup server - Because of this I'm using a custom cp wrapper
cp_rsnapshot_wrapper.sh - Snapshot roots:
/mnt/lback/rsnapshot(Linux) and/mnt/lback/rsnapshot-windows(Windows) - Each config has its own lockfile (
/var/run/rsnapshot.pid,/var/run/rsnapshot-windows.pid) and log file - Retention (in
default.inc): 6 daily, 3 weekly, 6 monthly sync_firstis enabled:rsnapshot syncdoes the rsync into.sync/, and the interval commands (daily,weekly,monthly) only rotate
Prerequisites
rsnapshotinstalled- SSH as root user must work from backup server to all targets
- It's recommended to use WSL in mirrored networking mode and change Windows native OpenSSH to use a port other than 22 in order to not interfere with WSL SSH
- If you use WSL NAT networking mode you need to set up SSH proxy to go through Windows SSH -> WSL SSH
- A working
mailcommand and MTA on the backup server, for the email reports
Filesystem Structure
Configuration files are under /etc/rsnapshot:
/etc/rsnapshot
├── default.inc # settings shared by both configs (included by each)
├── excludes.inc # Linux excludes
├── excludes-windows.inc # Windows excludes
├── rsnapshot.conf # Linux config
└── rsnapshot-windows.conf # Windows config
/etc/systemd/system
├── rsnapshot-nightly.service
└── rsnapshot-nightly.timer
/usr/local/bin
├── cp_rsnapshot_wrapper.sh
├── rsnapshot-nightly.sh
└── rsnapshot-report.sh
/var/log/rsnapshot
├── rsnapshot.log
└── rsnapshot-windows.log
NOTE: The conf directory contains Debian default files for reference. The excludes directory contains some example AI-generated excludes.
Configuration
Vim modeline
rsnapshot configuration files require tabs between options and their values/arguments.
To make life easier, this Vim modeline displays tabs as >- characters so you can visualize tabs in the configuration files:
# vim:syntax=conf:noexpandtab:ts=2:softtabstop=2:list:listchars=tab\:>-:
Retries and interrupted transfers
A brief network outage (e.g. changing a router setting) can kill an rsync over SSH mid-transfer, often with an error like ssh_dispatch_run_fatal: ... message authentication code incorrect. rsnapshot retries the failed backup point instead of giving up, controlled by these settings in default.inc:
rsync_numtries 5
rsync_wait_between_tries 60
rsync_numtriesdefaults to 1 (no retries).rsync_wait_between_triesdefaults to 0, which retries immediately. That only survives a momentary glitch; a router reboot lasting a minute or two would use up every retry before the network came back. With 60 seconds, a backup point that never recovers adds at most 4 minutes to the run.
Both configs also add --partial to rsync_long_args, so a retry resumes a large file that was cut off instead of starting it over:
# rsnapshot.conf
rsync_long_args --delete --numeric-ids --relative --delete-excluded --partial
# rsnapshot-windows.conf
rsync_long_args --delete --numeric-ids --relative --delete-excluded --no-perms --no-owner --no-group --modify-window=2 --partial
Caveat: if every retry fails, the truncated file is left in .sync/ under its real name and rotated into daily.0. That run will log returned N while processing and completed, but with some errors, and the report will say so.
rsnapshot only logs retrying rsync at loglevel 5, so at the default loglevel 3 a run that recovered on a later attempt otherwise looks clean. rsnapshot-report.sh catches this: a run that completed successfully but contains SSH/rsync connection errors is reported as SUCCESS after retry (see rsnapshot-report.sh).
Remember that rsync_long_args replaces rsnapshot's default arguments rather than adding to them, so it has to repeat the defaults (--delete --numeric-ids --relative --delete-excluded) along with anything extra.
Testing rsnapshot
Check each config after any edit:
rsnapshot -c /etc/rsnapshot/rsnapshot.conf configtest
rsnapshot -c /etc/rsnapshot/rsnapshot-windows.conf configtest
Show what a whole night would do without changing anything (runs every step with rsnapshot -t and skips the reports):
sudo /usr/local/bin/rsnapshot-nightly.sh -n
In a dry run, daily ends with ERROR: sync_first is enabled but there is no .sync directory. That's expected: -t only prints the sync commands, so .sync/ never gets created, and the last real run already rotated the previous .sync/ into daily.0. A real run creates .sync/ before daily checks for it.
Scheduling (systemd)
How a night runs
One timer, rsnapshot-nightly.timer, starts rsnapshot-nightly.sh at 01:55 every night. For each config in turn (Linux, then Windows) it runs:
| Step | When | What it does |
|---|---|---|
sync |
every night | rsync from the sources into .sync/ |
monthly |
the 1st of the month | rotates the oldest weekly to monthly.0 |
weekly |
Sundays | rotates the oldest daily to weekly.0 |
daily |
if sync exited 0 or 2 | rotates .sync/ to daily.0 |
| report | every night | one email covering every level that ran |
Why it's built this way:
- Longer intervals rotate first. rsnapshot requires monthly before weekly before daily.
synconly writes to.sync/, so running it first doesn't affect the monthly/weekly rotations. - One sync per night. The old per-level timers each ran their own
sync, so the 1st of the month copied everything from the sources three times. - No overlaps or idle gaps. Each step starts when the previous one finishes, so a slow night can't make one run collide with the next one's lockfile, and the Windows backup starts as soon as Linux is done.
- Warnings don't block the rotation. rsnapshot exits 0 on success, 1 on fatal errors and 2 on warnings only (e.g. rsync 23 "some files could not be transferred" from locked Windows files, or 24 "vanished"). A snapshot with warnings is still usable, so
dailyruns after exit 0 or 2 and is skipped only after a fatal error. Monthly and weekly only rotate existing snapshots, so they run even if that night's sync fails. - systemd sees failures. The service ends
failedif any step exits 1, so it shows up insystemctl list-units --failed. - Missed nights catch up.
Persistent=trueruns the backup at the next boot if the server was off at 01:55. - Low priority. The service runs with
Nice=10and best-effort I/O priority 7, so it yields to everything else on the server.
All machines are on Phoenix time (MST, no DST), so the 01:00–03:00 slot is safe. On a DST timezone, a run scheduled in the hour that is skipped or repeated at the clock change would be missed or run twice.
Installing the timer
sudo install -m 755 rsnapshot-nightly.sh rsnapshot-report.sh /usr/local/bin/
sudo install -m 644 rsnapshot-nightly.service rsnapshot-nightly.timer /etc/systemd/system/
sudo systemctl daemon-reload && sudo systemctl enable --now rsnapshot-nightly.timer
systemctl list-timers rsnapshot-nightly.timer
Check the last run:
journalctl -u rsnapshot-nightly.service --since today
systemctl status rsnapshot-nightly.service
journalctl shows each step and its exit code. A good night ends inactive (dead) with status=0/SUCCESS.
Don't start rsnapshot-nightly.service by hand after the timer has already run that day. Every run does a daily rotation (and weekly/monthly on Sundays and the 1st), so a second run pushes the oldest snapshot out a day early. To test, use the dry run (-n).
Migrating from per-level timers
This setup replaces six per-level timers (rsnapshot-{daily,weekly,monthly} and rsnapshot-windows-{daily,weekly,monthly}). To switch over:
sudo systemctl disable --now rsnapshot-daily.timer rsnapshot-weekly.timer rsnapshot-monthly.timer rsnapshot-windows-daily.timer rsnapshot-windows-weekly.timer rsnapshot-windows-monthly.timer
After a few clean nights, remove the old unit files:
sudo rm /etc/systemd/system/rsnapshot-{daily,weekly,monthly,windows-daily,windows-weekly,windows-monthly}.{service,timer} && sudo systemctl daemon-reload
Don't use /etc/cron.d/rsnapshot
The Debian package ships /etc/cron.d/rsnapshot. With the systemd timer in place, delete it so backups can't run twice:
sudo rm /etc/cron.d/rsnapshot
It's a dpkg conffile, and dpkg won't recreate a deleted conffile on upgrade.
rsnapshot-report.sh
This is a custom e-mail report generator created by Claude.ai that works better than rsnapreport.pl. rsnapshot-nightly.sh calls it once per config. It should be placed in /usr/local/bin and made executable:
chmod +x /usr/local/bin/rsnapshot-report.sh
Options:
-l LEVELS level(s) that ran, comma-separated in order, e.g. "daily" or "monthly,weekly,daily" (default: daily)
-t LABEL label for the subject, e.g. "Linux" or "Windows" (default: hostname)
-f LOGFILE rsnapshot log to parse (default: /var/log/rsnapshot.log)
It reports on the most recent run only: everything from the last sync: started line to the end of the log. The status is SUCCESS only if every level listed in -l logged <level>: completed successfully.
| Subject | Meaning |
|---|---|
rsnapshot Linux daily - 2026-11-02 |
every level completed, no errors |
rsnapshot Linux monthly+weekly+daily - 2026-11-01 |
same, on a night when monthly and weekly also ran |
rsnapshot RETRY - Linux daily - ... |
completed, but a transfer was interrupted and recovered on a retry; lists the affected backup points |
rsnapshot ERROR - Linux daily - ... |
a level failed or never ran (e.g. daily skipped after a failed sync) |
rsnapshot WARNING - no run today - Linux |
the most recent run in the log isn't from today |
Note: Check your logs to examine the datestamps at line beginnings. Make sure the date field separator character is the same as those in this line:
# hyphen separators:
TODAY="$(date '+%Y-%m-%d')"
# slash separators:
TODAY="$(date '+%Y/%m/%d')"
Use the one that corresponds with the date field separators in your rsnapshot log files.
Log files
sudo mkdir -p /var/log/rsnapshot
sudo touch /var/log/rsnapshot/rsnapshot.log /var/log/rsnapshot/rsnapshot-windows.log
/etc/logrotate.d/rsnapshot
/var/log/rsnapshot/rsnapshot.log {
daily
create 640 root adm
rotate 12
dateext
dateformat -%Y-%m-%d
notifyempty
}
/var/log/rsnapshot/rsnapshot-windows.log {
daily
create 640 root adm
rotate 12
dateext
dateformat -%Y-%m-%d
notifyempty
}
Invoking manually
It's recommended to run rsnapshot sync and rsnapshot daily manually the first time or even several times in order to check for errors and verify that it's running smoothly before enabling the timer.
You should see daily.0, daily.1, etc. in your backup directory for every time you run it. Inspect the logs during/after running it and look for critical errors. Some files failing to transfer due to permission issues are not critical errors.
Every manual daily is an extra rotation. Once the timer is running, a manual run on top of that night's run pushes the oldest daily out a day early.
If manually invoking via remote shell session it's also recommended to use a tmux session to gracefully handle any disconnects:
# in first window:
tail -F /var/log/rsnapshot/rsnapshot.log
# or:
tail -F /var/log/rsnapshot/rsnapshot-windows.log
# in second window:
tmux new -s rsnapshot
# 4 possible ways to manually run:
## 1. The whole nightly run: both configs, every level due today, email reports
sudo /usr/local/bin/rsnapshot-nightly.sh
## 2. One config, sync + daily, with email report (daily runs unless sync hit a fatal error, same as the nightly script)
sudo sh -c 'rsnapshot -c /etc/rsnapshot/rsnapshot.conf sync; [ $? -ne 1 ] && rsnapshot -c /etc/rsnapshot/rsnapshot.conf daily; /usr/local/bin/rsnapshot-report.sh -l daily -t Linux -f /var/log/rsnapshot/rsnapshot.log'
sudo sh -c 'rsnapshot -c /etc/rsnapshot/rsnapshot-windows.conf sync; [ $? -ne 1 ] && rsnapshot -c /etc/rsnapshot/rsnapshot-windows.conf daily; /usr/local/bin/rsnapshot-report.sh -l daily -t Windows -f /var/log/rsnapshot/rsnapshot-windows.log'
## 3. Create output suitable for parsing errors & warnings
sudo rsnapshot -V -c /etc/rsnapshot/rsnapshot.conf sync 2>&1 | grep -i "error\|warning\|cannot\|failed\|skip" | head -50
sudo rsnapshot -V -c /etc/rsnapshot/rsnapshot-windows.conf sync 2>&1 | grep -i "error\|warning\|cannot\|failed\|skip" | head -50
## 4. Or just simply:
sudo rsnapshot -c /etc/rsnapshot/rsnapshot.conf sync
sudo rsnapshot -c /etc/rsnapshot/rsnapshot.conf daily
sudo rsnapshot -c /etc/rsnapshot/rsnapshot-windows.conf sync
sudo rsnapshot -c /etc/rsnapshot/rsnapshot-windows.conf daily
Ctrl-b d detaches the tmux session.
tmux attach -t rsnapshot reattaches it.
Excludes
- Excludes are kept in separate files for convenience:
excludes.inc(Linux) andexcludes-windows.inc(Windows) - Because of
--delete-excluded, a newly added exclude also removes those files from the next snapshot; older snapshots keep them until they rotate out
It is recommended to use AI to help generate excludes.
For example you can ask Claude.ai "Please generate rsnapshot excludes for Android Studio, Vivaldi, VMware, and Hyper-V".
You can also feed Claude your log files and ask it to generate excludes based on any errors it parses. It's common for some files to fail to transfer due to permission issues. These files are usually unnecessary and should be excluded.
Fast-changing caches are also worth excluding because they grow every snapshot. For example, in excludes.inc:
/home/*/.vscode-server/data/logs/
/home/*/.vscode-server/bin/
/home/*/.vscode-server/cli/
Honing Excludes
# show the 30 top-level folders with the most files
cd /mnt/c/Users/<user>/AppData/Roaming
for d in */; do
echo "$(find "$d" -type f | wc -l) $d"
done | sort -rn | head -30
# go two levels deep into each of top directories and show biggest file-count subfolders
cd /mnt/c/Users/<user>/AppData/Roaming
for top in Zoom "Telegram Desktop" Kodi NVIDIA Adobe Google Code uv JetBrains Slack MediaMonkey5 LibreOffice Microsoft Steinberg Figma ZoiteChat Thunderbird Claude Ableton; do
echo "=== $top ==="
find "$top" -mindepth 1 -maxdepth 2 -type d 2>/dev/null | while read -r d; do
n=$(find "$d" -maxdepth 1 -type f 2>/dev/null | wc -l)
[ "$n" -gt 0 ] && echo "$n $d"
done | sort -rn | head -5
echo
done