Logo

dev-resources.site

for different kinds of informations.

Fixing Linux Backup Sync Issues for exFAT Compatibility

Published at
1/11/2025
Categories
linux
exfat
bash
microsoft
Author
wvrossem
Categories
4 categories in total
linux
open
exfat
open
bash
open
microsoft
open
Author
8 person written this
wvrossem
open
Fixing Linux Backup Sync Issues for exFAT Compatibility

A recent issue with synchronizing my home directory to my exFAT-formatted external SSD surfaced while using KDE’s Kup Backup application. Errors occurred because some filenames contained characters not supported by the exFAT file system.

Understanding exFAT's Filename Restrictions

Many external drives use exFAT for cross-platform compatibility. However, exFAT prohibits certain characters in filenames, which can cause issues when backing up files from Linux filesystems.

Filenames can include all Unicode characters except:

  • " (double quote)
  • * (asterisk)
  • : (colon)
  • < (less than)
  • > (greater than)
  • ? (question mark)
  • \ (backslash)
  • / (forward slash)
  • | (pipe)

Filenames also cannot end with a space or a period, but these cases are not currently handled by the script below.

Identifying Problematic Files

Kup Backup logs errors related to such files in ~/.cache/kup/kup_plan1.log. Reviewing this log allowed me to isolate the problematic files. If only a few files are affected, the simple solution is to manually rename them, removing or replacing any unsupported characters.

Automating the Renaming Process with a Bash Script

For a large number of files, the renaming process can be automated. The following Bash script (corrected from an initial version created with ChatGPT) identifies and renames files in given directories that contain invalid characters, replacing each with an underscore.

#!/bin/bash

# Directories to scan
directories=(
    "/path/to/your/directory1"
    "/path/to/your/directory2"
)

# Array of characters to replace
declare -A char_map=(
    ['"']='_'
    ['*']='_'
    [':']='_'
    ['<']='_'
    ['>']='_'
    ['?']='_'
    ['\\']='_'
    ['/']='_'
    ['|']='_'
)

# Function to rename files
rename_files() {
    local dir="$1"
    # Use find to search for files in "$dir" with names containing restricted characters, 
    # then pass each result to the while loop for processing.
    find "$dir" -depth -name '*["*:<>?\\|]*' | while IFS= read -r file; do
        # Get the directory and base name of the file
        dir_path=$(dirname "$file")
        base_name=$(basename "$file")

        # Rename the file
        new_name="$base_name"
        for char in "${!char_map[@]}"; do
            new_name="${new_name//"$char"/${char_map[$char]}}"
        done

        # If the filename has changed, rename it
        if [[ "$base_name" != "$new_name" ]]; then
            mv -v -n "$file" "$dir_path/$new_name"
        fi
    done
}

# Iterate over directories and rename files
for dir in "${directories[@]}"; do
    if [[ -d "$dir" ]]; then
        rename_files "$dir"
    else
        echo "Directory $dir does not exist."
    fi
done
Enter fullscreen mode Exit fullscreen mode

How the Script Works

The script iterates over each specified directory, checks if it exists, and calls the rename_files function.

The rename_files function uses find to locate files with restricted characters in their names. It then iteratively replaces each restricted character with an underscore and renames the file using mv, with verbose flag to explain what is being done. The -n flag makes sure it will not overwrite an existing file.

Usage Instructions

I’ve tested the script, but remember to take precautions to prevent data loss when running it.

After running the process, verify that the files were renamed correctly. Manual post-processing is needed for files that would have caused duplicate names (these files are skipped).

If you encounter any issues or have suggestions for improvements, feel free to reach out and let me know.

linux Article's
30 articles in total
Favicon
Easy development environments with Nix and Nix flakes!
Favicon
Setting Up a Simple Two-Node Kubernetes Cluster in No Time
Favicon
Nextcloud on Raspberry Pi - Fedora + Podman Quadlets
Favicon
NVIDIA Drivers with Secure Boot on Ubuntu
Favicon
Как создать свой VPN и получить доступ ко всему?
Favicon
How I used a named pipe to save memory and prevent crashes (in Perl)
Favicon
KDE vs GNOME vs Others: Choosing the Best Linux Desktop Environment in 2025
Favicon
The Linux Foundation Data and AI Fundamentals
Favicon
Kubernetes Security Best Practices
Favicon
A new shell for using modern alternatives to Unix commands
Favicon
Como configurar 2FA em Servidores Linux
Favicon
Configurar servidor de archivos local con Ubuntu y Samba
Favicon
Google Cloud Shell: Establishing Secure Connections via SSH
Favicon
Understanding Linux Shells: Interactive, Non-Interactive, and RC Files
Favicon
[Boost]
Favicon
I am going to learn java in next 8 weeks, please follow me for regular updates
Favicon
Configuring network access with Cisco ASA via minicom utility
Favicon
Fixing Linux Backup Sync Issues for exFAT Compatibility
Favicon
Enhance Your macOS Terminal with Oh My Zsh, Autosuggestions, and Powerlevel10k
Favicon
Turning Markdown into Learning: publishing a challenge on labs.iximiuz.com
Favicon
Fixes for a critical rsync vulnerability (CVE-2024-12084) have been released for Stable/Bookworm, Testing and Unstable....
Favicon
My Zig with Ghostty
Favicon
Understanding Node Problem Detector in Kubernetes: Beyond Default Node Conditions
Favicon
Nginx Simplified: Technical Insights with Real-World Analogies
Favicon
GNOME vs KDE Plasma: Which One Is for You?
Favicon
SSH Keys | Change the label of the public key
Favicon
Debian and KDE 6 - WSL - How to install KDE 6 via Debian - Windows 11 - X410 - Linux - 2024 https://www.youtube.com/watch?v=yrtgmwsptVc
Favicon
Linux/Unix login overview and a bit of clever tricks with "history"
Favicon
🏆 Branching to Level Up in the Cloud! ☁️
Favicon
Mastering Linux File Systems: Everything You Need to Know About Symlinks and Hard Links

Featured ones: