diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
index df3021c1f09338d2df0e4175cabb258936ab811a_aGdleHQvbGFyZ2VmaWxlcy9sZnV0aWwucHk=..1e98f9b5bc71d212b9efcf9404855fd29c6a7aca_aGdleHQvbGFyZ2VmaWxlcy9sZnV0aWwucHk= 100644
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -195,6 +195,8 @@
         # (1) disable PENDING mode always
         #     (lfdirstate isn't yet managed as a part of the transaction)
         # (2) avoid develwarn 'use dirstate.write with ....'
+        if tr:
+            tr.addbackup(b'largefiles/dirstate', location=b'plain')
         super(largefilesdirstate, self).write(None)
 
 
diff --git a/tests/test-largefiles-cache.t b/tests/test-largefiles-cache.t
index df3021c1f09338d2df0e4175cabb258936ab811a_dGVzdHMvdGVzdC1sYXJnZWZpbGVzLWNhY2hlLnQ=..1e98f9b5bc71d212b9efcf9404855fd29c6a7aca_dGVzdHMvdGVzdC1sYXJnZWZpbGVzLWNhY2hlLnQ= 100644
--- a/tests/test-largefiles-cache.t
+++ b/tests/test-largefiles-cache.t
@@ -185,7 +185,8 @@
 
   $ find share_dst/.hg/largefiles/* | sort
   share_dst/.hg/largefiles/dirstate
+  share_dst/.hg/largefiles/undo.backup.dirstate
 
   $ find src/.hg/largefiles/* | egrep "(dirstate|$hash)" | sort
   src/.hg/largefiles/dirstate
   src/.hg/largefiles/e2fb5f2139d086ded2cb600d5a91a196e76bf020
@@ -188,7 +189,8 @@
 
   $ find src/.hg/largefiles/* | egrep "(dirstate|$hash)" | sort
   src/.hg/largefiles/dirstate
   src/.hg/largefiles/e2fb5f2139d086ded2cb600d5a91a196e76bf020
+  src/.hg/largefiles/undo.backup.dirstate
 
 Verify that backwards compatibility is maintained for old storage layout
   $ mv src/.hg/largefiles/$hash share_dst/.hg/largefiles