# All data deleted when restore external snapshot on psmdb

**URL:** <https://forums.percona.com/t/all-data-deleted-when-restore-external-snapshot-on-psmdb/39957>\
**Category:** Percona Backup for MongoDB\
**Tags:** percona\
**Created:** [December 31, 2025, 6:20am UTC](https://forums.percona.com/t/all-data-deleted-when-restore-external-snapshot-on-psmdb/39957 "2025-12-31T06:20:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaobao\_wen](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/xiaobao_wen/32/22407_2.png) [@xiaobao\_wen](https://forums.percona.com/u/xiaobao_wen)\
**Post date:** [December 31, 2025, 6:20am UTC](https://forums.percona.com/t/all-data-deleted-when-restore-external-snapshot-on-psmdb/39957/1 "2025-12-31T06:20:36Z")

</div>

> <https://github.com/percona/percona-backup-mongodb/blob/7e76039e52acbe33c1f614817bc9d7b7b51bb358/pbm/restore/physical.go#L1372>

After restore status become StatusCopyDone, pbm agent cleanupDatadir with needFiles. filepath.Walk cannot enter symlink directory.

/data/db/journal may be wrongly deleted

```auto
[mongodb@dev-rs-mdb-rs0-2 /]$ ls /data/db/ -l | grep journal

lrwxrwxrwx 1 mongodb 1001 8 Dec 5 07:05 journal -> /journal

```

---

<div class="post-metadata">

**Author:** ![anderson.nogueira](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/anderson.nogueira/32/23141_2.png) [@anderson.nogueira](https://forums.percona.com/u/anderson.nogueira)\
**Post date:** [February 20, 2026, 5:49pm UTC](https://forums.percona.com/t/all-data-deleted-when-restore-external-snapshot-on-psmdb/39957/2 "2026-02-20T17:49:45Z")

</div>

Hi @xiaobao_wen,

I was able to reproduce this with standalone Go experiments that extract the exact `cleanupDatadir` logic from PBM v2.12.0 (`physical.go` [L1344](https://github.com/percona/percona-backup-mongodb/blob/v2.12.0/pbm/restore/physical.go#L1344)). You pinpointed the right spot.

The root cause is that Go’s `filepath.Walk` [does not follow symbolic links](https://pkg.go.dev/path/filepath#Walk). When Walk encounters your `journal -> /journal` symlink, it reports `info.IsDir() == false` (because it is a symlink, not a directory). The guard on [L1376](https://github.com/percona/percona-backup-mongodb/blob/v2.12.0/pbm/restore/physical.go#L1376) only protects real directories. Since `"journal"` is not a file in the backup manifest (files are listed as `journal/WiredTigerLog.xxx`), the cleanup treats the symlink as an orphan file and calls `os.Remove` on it. The journal files survive on your separate volume but become unreachable from the dbpath.

There is actually a second failure point: the `removeAll` function ([L2856](https://github.com/percona/percona-backup-mongodb/blob/v2.12.0/pbm/restore/physical.go#L2856)) called during `flush()` also destroys symlinks via `os.RemoveAll` with no type checking.

The fix for `cleanupDatadir` is a one-line guard before the `IsDir` check:

```go
if info.Mode()&os.ModeSymlink != 0 {
    return nil
}

```

`removeAll` needs a similar guard using `os.Lstat` to detect and skip symlinks in its loop.

**Workaround for now:** after each physical restore, recreate the symlink before starting mongod:

```bash
rm -rf /data/db/journal
ln -s /journal /data/db/journal

```

This bug affects all PBM 2.x versions. I filed [PBM-1706](https://perconadev.atlassian.net/browse/PBM-1706) to track the fix.
