diff --git a/liquibase-core/src/main/java/liquibase/changelog/OfflineChangeLogHistoryService.java b/liquibase-core/src/main/java/liquibase/changelog/OfflineChangeLogHistoryService.java
index <HASH>..<HASH> 100644
--- a/liquibase-core/src/main/java/liquibase/changelog/OfflineChangeLogHistoryService.java
+++ b/liquibase-core/src/main/java/liquibase/changelog/OfflineChangeLogHistoryService.java
@@ -222,11 +222,11 @@ public class OfflineChangeLogHistoryService extends AbstractChangeLogHistoryServ
                     csvWriter.writeNext(line);
                 }
             }
-            oldFile.delete();
-            newFile.renameTo(oldFile);
         } catch (Exception e) {
             throw new DatabaseException(e);
         }
+        oldFile.delete();
+        newFile.renameTo(oldFile);
     }
 
     protected void appendChangeSet(ChangeSet changeSet, ChangeSet.ExecType execType) throws DatabaseException {
@@ -265,11 +265,12 @@ public class OfflineChangeLogHistoryService extends AbstractChangeLogHistoryServ
 
             csvWriter.writeNext(newLine);
 
-            oldFile.delete();
-            newFile.renameTo(oldFile);
         } catch (Exception e) {
             throw new DatabaseException(e);
         }
+        
+        oldFile.delete();
+        newFile.renameTo(oldFile);
     }
 
     @Override
closing streams before rename

(cherry picked from commit b8c<I>afe7c<I>da<I>ef5f<I>e6a0bed6)