
How to search hierarchical data for files and folder in the Hyper Backup Structure. The backup job should not be encrypted.
search method 1:
Backup structure on USB-disk
The .hbk on your USB disk is a backup archive.
You can try mounting the archive in DSM
- With the USB disk connected to your NAS, open File Station and locate the
.hbkarchive on the USB share Right-click the
.hbkand select Mount Hyper Backup destination if the option is available. Choose a DSM shared folder that only authorized users can access as the mount destination.Open the mounted backup in File Station and navigate to the backed-up shared folder you want to search. Try entering part of the filename in the search box. If File Station search is unavailable in that view and you already have SSH access, change to the directory for that mounted backup folder and run:
find . -iname ‘*part-of-filename*’
Replace part-of-filename with the text you’re looking for. This lists matching files and folders at any depth under your current directory. It only searches the contents visible at that path, so an empty result doesn’t rule out a match in an older backup version.
search method 2:
If the mount option is unavailable, or you need to search a specific older version, right-click the .hbk and choose:
- Open Backup Explorer.
- Select the date on the timeline
- Select the backed-up shared folder, and use Copy to… to copy it to a separate temporary folder on the NAS.
- You can then open that temporary folder in File Station and search all its subfolders. Repeat for any other version you need to check.
How do I run scripts from Synology Task Scheduler and how do I create scripts?
Click here for instructions how to create scripts and run those scripts from the Synology Task Scheduler in Control Panel.
Warning
Warning: always test scripts in a testing environment before usage, use at your own risk
search method 3
use a script and run it from Task Scheduler
user: root
user-defined script: for example
bash /volume1/scripts/searchhyper.sh. Please change accordingly:
HKB_DIR=”/volumeUSB1/usbshare/test.hbk”
KEYWORD=”test”
OUTPUT=”/volume1/scripts/searchhyper-results.txt”
Script 1: /volume1/scripts/searchhyper.sh
#!/usr/bin/env bash
HKB_DIR=”/volumeUSB1/usbshare/test.hbk”
KEYWORD=”test”
OUTPUT=”/volume1/scripts/searchhyper-results.txt”
VERSION_DB=”$HKB_DIR/Config/version_info.db”
find “$HKB_DIR” -name “1.db” | while read db; do
results=$(sqlite3 -separator ‘|’ “$db” “
WITH RECURSIVE path_tree AS (
SELECT name_id_v2 AS orig_id, name_id_v2, pname_id_v2,
CAST(file_name AS TEXT) AS full_path,
0 AS depth
FROM version_list
WHERE file_name LIKE ‘%$KEYWORD%’
AND file_name NOT LIKE ‘%@SynoEAStream’
AND file_name NOT LIKE ‘%@SynoResource%’
AND file_name NOT LIKE ‘%@eaDir%’
UNION ALL
SELECT t.orig_id, p.name_id_v2, p.pname_id_v2,
p.file_name || ‘/’ || t.full_path,
t.depth + 1
FROM version_list p
JOIN path_tree t ON p.name_id_v2 = t.pname_id_v2
WHERE p.file_name NOT LIKE ‘%@eaDir%’
AND p.file_name NOT LIKE ‘%@SynoEAStream’
AND p.file_name NOT LIKE ‘%@SynoResource%’
AND t.depth < 50
)
SELECT pt.full_path, v.mode, v.version_id
FROM path_tree pt
JOIN version_list v ON v.name_id_v2 = pt.orig_id
WHERE pt.depth = (SELECT MAX(depth) FROM path_tree pt2 WHERE pt2.orig_id = pt.orig_id);
“)
if [ -n “$results” ]; then
echo “=== $db ===”
echo “path|type|backup_date”
echo “$results” | while IFS=’|’ read -r path mode verid; do
if [ $(( mode & 61440 )) -eq 16384 ]; then
type=”DIR”
else
type=”FILE”
fi
backup_date=$(sqlite3 “$VERSION_DB” “SELECT timestamp FROM version_info WHERE id=$verid;”)
readable=$(date -d “@${backup_date}” ‘+%Y-%m-%d %H:%M’)
echo “${path}|${type}|${readable}”
done
fi
done > “$OUTPUT”
echo “Results saved to $OUTPUT”
script 2
use a script and run it from Task Scheduler
user: root
user-defined script: for example
bash /volume1/scripts/searchhyper.sh. Please change accordingly:
HKB_DIR=”/volumeUSB1/usbshare/test.hbk”
KEYWORD=”test”
OUTPUT=”/volume1/scripts/searchhyper-results.txt”
Script 2: /volume1/scripts/searchhyper.sh
#!/usr/bin/env bash
HKB_DIR=”/volumeUSB1/usbshare/test.hbk”
KEYWORD=”test”
OUTPUT=”/volume1/scripts/searchhyper-results.txt”
# — Discover DB files —
DB_FILES=$(find “$HKB_DIR” -name “*.db” -type f | grep -v “version_info” | grep -v “complete_list”)
if [ -z “$DB_FILES” ]; then
echo “ERROR: No .db files found under $HKB_DIR”
echo “Run: find $HKB_DIR -name ‘*.db’ -type f | head -30”
exit 1
fi
# — Locate version_info.db —
VERSION_DB=$(find “$HKB_DIR” -name “version_info.db” -type f | head -1)
if [ -z “$VERSION_DB” ]; then
echo “ERROR: version_info.db not found”
exit 1
fi
echo “Using version DB: $VERSION_DB”
echo “Found $(echo “$DB_FILES” | wc -l) data DB files”
echo “”
# — Search —
{
echo “Keyword: $KEYWORD”
echo “Backup: $HKB_DIR”
echo “Date: $(date ‘+%Y-%m-%d %H:%M’)”
echo “================================================================”
echo “$DB_FILES” | while read db; do
results=$(sqlite3 -separator ‘|’ “$db” “
WITH RECURSIVE path_tree AS (
SELECT name_id_v2 AS orig_id, name_id_v2, pname_id_v2,
CAST(file_name AS TEXT) AS full_path,
0 AS depth
FROM version_list
WHERE file_name LIKE ‘%$KEYWORD%’
AND file_name NOT LIKE ‘%@SynoEAStream’
AND file_name NOT LIKE ‘%@SynoResource%’
AND file_name NOT LIKE ‘%@eaDir%’
UNION ALL
SELECT t.orig_id, p.name_id_v2, p.pname_id_v2,
p.file_name || ‘/’ || t.full_path,
t.depth + 1
FROM version_list p
JOIN path_tree t ON p.name_id_v2 = t.pname_id_v2
WHERE p.file_name NOT LIKE ‘%@eaDir%’
AND p.file_name NOT LIKE ‘%@SynoEAStream’
AND p.file_name NOT LIKE ‘%@SynoResource%’
AND t.depth < 50
)
SELECT pt.full_path, v.mode, v.version_id
FROM path_tree pt
JOIN version_list v ON v.name_id_v2 = pt.orig_id
WHERE pt.depth = (SELECT MAX(depth) FROM path_tree pt2 WHERE pt2.orig_id = pt.orig_id);
“)
if [ -n “$results” ]; then
echo “=== $(basename “$db”) ===”
echo “path|type|backup_date”
echo “$results” | while IFS=’|’ read -r path mode verid; do
if [ $(( mode & 61440 )) -eq 16384 ]; then
type=”DIR”
else
type=”FILE”
fi
backup_date=$(sqlite3 “$VERSION_DB” “SELECT timestamp FROM version_info WHERE id=$verid;”)
readable=$(date -d “@${backup_date}” ‘+%Y-%m-%d %H:%M’)
echo “${path}|${type}|${readable}”
done
echo “”
fi
done
} > “$OUTPUT”
echo “Results saved to $OUTPUT”
echo “Lines: $(wc -l < “$OUTPUT”)”


