When a Space Becomes a Folder
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 [email protected]:/home my_folder/
backup [email protected]:/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 [email protected]:/home my_folder/
But what we actually had (when shown with cat -A) was:
backup^[email protected]:/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:
Run a test snapshot and verify:
rsnapshot alpha
ls /backup/rsnapshot/alpha.0/my_folder/
Clean up the misnamed folder:
rm -rf '/backup/rsnapshot/alpha.0/my_folder/ '
Remove trailing spaces from all lines:
sed -i 's/[ \t]*$//' /etc/rsnapshot.conf
Display trailing whitespace using cat -A:
cat -A /etc/rsnapshot.conf
Lessons Learned
- Whitespace matters — especially at the ends of lines in configuration files.
- Use
cat -Aorvim -bwhen you suspect hidden characters. - Be cautious with paths in backup tools like
rsnapshotorrsync; 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.