title: Jenkins: DirectoryNotEmptyException: .../lastSuccessful
body: <p>We are running Jenkins 1.651.1 in a Docker container.
  On a certain moment we decided to move our containers to another environment.</p>
  
  <p>We have a cron job which creates backups of the volume of our container:</p>
  
  <pre><code>tar -cvpzf jenkins-backup.tar -C jenkins-volume/_data/ . --exclude ".m2"
  </code></pre>
  
  <p>On the new environment we created a new jenkins docker volume:</p>
  
  <pre><code>docker volume create --name jenkins-volume
  </code></pre>
  
  <p>And we <code>untar</code> our backup inside the volume + recreated a jenkins instance and connected it with the volume</p>
  
  <p>Everything is working fine again except we sometimes get an unexpected 'error' message. It doesn't break anything but appears very often:</p>
  
  <pre><code>Started by user ********
  ln builds/lastSuccessfulBuild /var/jenkins_home/jobs/xxx/lastSuccessful failed
  java.nio.file.DirectoryNotEmptyException: /var/jenkins_home/jobs/xxx/lastSuccessful
      at sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:242)
      at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:108)
      at java.nio.file.Files.deleteIfExists(Files.java:1165)
      at sun.reflect.GeneratedMethodAccessor473.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at hudson.Util.createSymlinkJava7(Util.java:1233)
      at hudson.Util.createSymlink(Util.java:1151)
      at hudson.model.Run.createSymlink(Run.java:1840)
      at hudson.model.Run.updateSymlinks(Run.java:1821)
      at hudson.model.Run.execute(Run.java:1736)
      at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
      at hudson.model.ResourceController.execute(ResourceController.java:98)
      at hudson.model.Executor.run(Executor.java:410)
  ln builds/lastStableBuild /var/jenkins_home/jobs/xxx/lastStable failed
  java.nio.file.DirectoryNotEmptyException: /var/jenkins_home/jobs/xxx/lastStable
      at sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:242)
      at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:108)
      at java.nio.file.Files.deleteIfExists(Files.java:1165)
      at sun.reflect.GeneratedMethodAccessor473.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at hudson.Util.createSymlinkJava7(Util.java:1233)
      at hudson.Util.createSymlink(Util.java:1151)
      at hudson.model.Run.createSymlink(Run.java:1840)
      at hudson.model.Run.updateSymlinks(Run.java:1822)
      at hudson.model.Run.execute(Run.java:1736)
      at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
      at hudson.model.ResourceController.execute(ResourceController.java:98)
      at hudson.model.Executor.run(Executor.java:410)
  [EnvInject] - Loading node environment variables.
  Building in workspace /var/jenkins_home/jobs/xxx/workspace
   &gt; git rev-parse --is-inside-work-tree # timeout=10
  ... and it works further and fine
  </code></pre>
  
  <p>What is the best way to solve this?</p>