Esempio n. 1
0
  /**
   * Copies items from the temp DIR to the main DIR after ZIP if needed. After it has done the
   * required action, it deletes the source folder.
   *
   * @param sourceDIR The source directory. (ex: "backups/temp/xxxxxxxx")
   * @param finalDIR The final destination. (ex: "backups/xxxxxxxx")
   */
  public static void doCopyAndZIP(
      String sourceDIR, String finalDIR, boolean shouldZIP, boolean useTempFolder) {

    if (useTempFolder) {
      if (shouldZIP) {
        try {
          FileUtils.zipDir(sourceDIR, finalDIR);
        } catch (IOException ioe) {
          LogUtils.exceptionLog(ioe, "Failed to ZIP backup: IO Exception.");
        }
      } else {
        try {
          FileUtils.copyDirectory(sourceDIR, finalDIR);
        } catch (IOException ex) {
          Logger.getLogger(BackupTask.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
      try {
        // Delete the original doBackup directory.
        FileUtils.deleteDirectory(new File(sourceDIR));
        new File(sourceDIR).delete();
      } catch (IOException ioe) {
        LogUtils.exceptionLog(ioe, "Failed to delete temp folder: IO Exception.");
      }
    } else {
      if (shouldZIP) {
        try {
          FileUtils.zipDir(sourceDIR, finalDIR);
        } catch (IOException ioe) {
          LogUtils.exceptionLog(ioe, "Failed to ZIP backup: IO Exception.");
        }
        try {
          // Delete the original doBackup directory.
          FileUtils.deleteDirectory(new File(sourceDIR));
          new File(sourceDIR).delete();
        } catch (IOException ioe) {
          LogUtils.exceptionLog(ioe, "Failed to delete temp folder: IO Exception.");
        }
      }
    }
  }
Esempio n. 2
0
 public static boolean checkFolderAndCreate(File toCheck) {
   if (!toCheck.exists()) {
     try {
       if (toCheck.mkdirs()) {
         return true;
       }
     } catch (Exception e) {
       LogUtils.exceptionLog(e);
     }
   }
   return false;
 }