code: public static void backupFiles(FileSystem fs, File dest, 
        Configuration conf) throws IOException {
      // check if we can still backup
      cleanUpAndCheckBackup(conf, dest);
      
      int MAX_ATTEMPT = 3;
      for (int i = 0; i < MAX_ATTEMPT; i++) {
        try {
          String mdate = dateForm.get().format(new Date(System.currentTimeMillis()));
          if (dest.exists()) {
            File tmp = new File (dest + File.pathSeparator + mdate);
            FLOG.info("Moving aside " + dest + " as " + tmp);
            if (!dest.renameTo(tmp)) {
              throw new IOException("Unable to rename " + dest +
                                    " to " +  tmp);
            }
            FLOG.info("Moved aside " + dest + " as " + tmp);
          }
          return;
        } catch (IOException e) {
          FLOG.error("Creating backup exception. Will retry ", e);
          try {
            Thread.sleep(1000);
          } catch (InterruptedException iex) {
            throw new IOException(iex);
          }
        }
      }
      throw new IOException("Cannot create backup for: " + dest);
    }
docs: Backup given directory.
  Enforce that max number of backups has not been reached.