Previous versions on Linux
Implementing volume shadow copy functionality on the Linux desktop
Posted on: 2025-10-25
Snapshots are not backups, but they can still be a very useful way to restore individual files to previous versions. That's why most NAS solutions offer this as a feature, such as my own QNAP NAS. And in most cases, this is exposed on shared directories using the Volume Shadow Copy Service (VSS), also known in the Windows world as Previous Versions. This means that you can right-click a file, select Previous Versions, and get a list of past versions of that file that you can restore. Unfortunately, that functionality isn't available by default in Linux, even though it's fairly trivial to add, so I decided to write a short script to implement similar functionality.
This script works for my own NAS and should work in any situation where shadow copies are exposed in some way through the SMB protocol. The exact location and method may vary based on your specific files server. I'll also show you how to add it as a right-click item in Thunar, the default file manager on XFCE4, but there are ways to add it on most other Linux desktop environments.
The script
Create the file /usr/bin/list_snapshots and save the following Bash script:
#!/bin/bash
# Provides a 'Previous Versions' dialog with restore functionality
fullpath="$1"
sharedir="/share"
snapdir="$sharedir/@Recently-Snapshot"
# Make sure the file is within the share directory
if [[ "$fullpath" != $sharedir/* ]]; then
zenity --error --title "Previous Versions" --text="This script only works for files under:\n$sharedir"
exit 1
fi
# Find snapshots and index them in a temp file
file="${fullpath#$sharedir/}"
last_size=""
last_mtime=""
tmpfile=$(mktemp)
{
num=0
echo "# Scanning..."
for snap in "$snapdir"/GMT-*; do
snap_file="$snap/$file"
if [ -f "$snap_file" ]; then
read size mtime <<< $(stat -c "%s %Y" "$snap_file")
if [[ "$size" != "$last_size" || "$mtime" != "$last_mtime" ]]; then
((num++))
echo "# Scanning... Found $num snapshots."
last_size="$size"
last_mtime="$mtime"
date_str=$(date -d @"$mtime" "+%Y-%m-%d %H:%M")
size_kb=$((size / 1024))
printf "%s\t%s\t%s\n" "$(basename "$snap")" "$date_str" "$size_kb" >>"$tmpfile"
fi
fi
done
echo "100"
} | zenity --progress --title="Previous Versions" --text="Please wait..." --auto-close --pulsate
# User pressed the Cancel button
if [ "$?" != 0 ] ; then
exit
fi
# Read temp file
mapfile -t snapshot_rows <"$tmpfile"
rm -f "$tmpfile"
# No snapshots were found
if [ ${#snapshot_rows[@]} -eq 0 ]; then
zenity --info --title "Previous Versions" --text="No snapshots found for:\n$file"
exit
fi
# Prepare data for dialog box
list_args=()
for line in "${snapshot_rows[@]}"; do
IFS=$'\t' read -r snap_name date_str size_kb <<<"$line"
list_args+=("$snap_name" "$date_str" "$size_kb")
done
# Show found snapshots
selected=$(zenity --list --title="Previous Versions" \
--text "Select a snapshot to restore:" --column="Snapshot" --column="Date & Time" --column="Size (KB)" \
"${list_args[@]}" --ok-label "Restore" --print-column=1 --width=600 --height=400)
# Restore a snapshot
if [ -n "$selected" ]; then
src="$snapdir/$selected/$file"
dst="$sharedir/$file"
if [ ! -f "$src" ]; then
zenity --error --title="Previous Versions" \
--text="Snapshot could not be found:\n$src"
exit 1
fi
# Try to restore, capturing stderr
if ! err=$(cp -p "$src" "$dst" 2>&1); then
zenity --error --title="Previous Versions" \
--width=500 \
--text="Failed to restore:\n$file\n\n$err"
exit 1
fi
zenity --info --title="Previous Versions" \
--text="Successfully restored:\n$file"
fi
If you'll notice at the top, I assume that your shared drive is mounted at /share and has a visible folder with the snapshots. Adjust as needed. Then make sure you make the script executable with:
chmod +x /usr/bin/list_snapshots
You can test it from the command line and it should produce the following screens. First, it will look for snapshots for that specific file:

Then it will show you a list of snapshots. Click on Restore to restore the file:

Finally it will tell you if the restore was successful:

File manager integration
In Thunar, go to the Edit menu and select Configure custom actions. There, enter a name, icon and the following command:
/usr/bin/list_snapshots %f
Make sure you enable it for all file types and save it.

And that's it, you should now see a new right-click option that will list previous versions of files, similar to the Windows functionality.