When a Space Becomes a Folder: Debugging a Weird rsnapshot Glitch

mauvehedmauvehed
2 min read

While maintaining backups across several Linux hosts using rsnapshot, I ran into a deceptively simple but confusing issue: some directories from a remote host were being backed up into a folder literally named ' ' (a single space character). It looked like this:

/backup/rsnapshot/alpha.0/my_folder/ /

Inside that ghostly folder? The expected contents of /home, /usr/local, and other critical directories from a remote server. But why?

Initial Clue: A Mysterious Folder

Running a directory listing revealed something fishy:

root@darkstar:/backup/rsnapshot# ls -l alpha.0/my_folder
total 24
drwxr-xr-x   5 root root  4096 Nov 11  2023 ' '
drwxr-xr-x 111 root root 12288 May 18 07:54 etc
drwx------  14 root root  4096 May 21 14:36 root
drwxr-xr-x  13 root root  4096 May  2  2021 var

Notice the first entry: ' '. A folder literally named with a single space. Inside that directory were:

/backup/rsnapshot/alpha.0/my_folder/ /home
/backup/rsnapshot/alpha.0/my_folder/ /usr
...

The Setup

We're using rsnapshot to pull backups from various hosts via SSH, with config entries like:

backup  root@remote.example.org:/home        my_folder/
backup  root@remote.example.org:/usr/local   my_folder/

Each host gets its own backup root (my_folder/, other_folder/, etc.), and within each, rsnapshot maintains timestamped snapshots (alpha.0, alpha.1, etc.).

The Culprit: A Trailing Space

Turns out, the issue came from a silent but deadly character: a trailing space after the destination path in rsnapshot.conf.

This is what we thought we had:

backup  root@remote.example.org:/home        my_folder/

But what we actually had (when shown with cat -A) was:

backup^Iroot@remote.example.org:/home^Imy_folder/ $

That space at the end meant the destination directory was interpreted as "my_folder/ " (note the space), so rsnapshot faithfully placed the backup contents there. And thus, we ended up with:

/backup/rsnapshot/alpha.0/my_folder/ /

The issue only affected some remote sources — those that had accidental trailing spaces.

The Fix

To clean things up:

  1. Display trailing whitespace using cat -A:

     cat -A /etc/rsnapshot.conf
    
  2. Remove trailing spaces from all lines:

     sed -i 's/[ \t]*$//' /etc/rsnapshot.conf
    
  3. Clean up the misnamed folder:

     rm -rf '/backup/rsnapshot/alpha.0/my_folder/ '
    
  4. Run a test snapshot and verify:

     rsnapshot alpha
     ls /backup/rsnapshot/alpha.0/my_folder/
    

Lessons Learned

  • Whitespace matters — especially at the ends of lines in configuration files.

  • Use cat -A or vim -b when you suspect hidden characters.

  • Be cautious with paths in backup tools like rsnapshot or rsync; trailing slashes and spaces can drastically change behavior.

  • Consider running a config linter or writing a pre-check script to avoid these subtle bugs in production environments.

0
Subscribe to my newsletter

Read articles from mauvehed directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

mauvehed
mauvehed

I am a recovering technologist who fell in love with people management & leadership.