001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2008-2009 Sun Microsystems, Inc.
025 *      Portions Copyright 2014-2015 ForgeRock AS
026 */
027
028package org.opends.guitools.controlpanel.ui;
029
030import static org.opends.messages.AdminToolMessages.*;
031
032import java.awt.Component;
033import java.awt.GridBagConstraints;
034import java.awt.GridBagLayout;
035import java.io.File;
036import java.text.SimpleDateFormat;
037import java.util.ArrayList;
038import java.util.Collection;
039import java.util.Date;
040import java.util.HashSet;
041import java.util.LinkedHashSet;
042import java.util.Set;
043import java.util.TreeSet;
044
045import org.forgerock.i18n.LocalizableMessage;
046import org.forgerock.i18n.slf4j.LocalizedLogger;
047
048import javax.swing.ButtonGroup;
049import javax.swing.DefaultComboBoxModel;
050import javax.swing.JCheckBox;
051import javax.swing.JComboBox;
052import javax.swing.JComponent;
053import javax.swing.JLabel;
054import javax.swing.JPanel;
055import javax.swing.JRadioButton;
056import javax.swing.JTextField;
057import javax.swing.SwingUtilities;
058import javax.swing.event.ChangeEvent;
059import javax.swing.event.ChangeListener;
060
061import org.opends.guitools.controlpanel.datamodel.BackendDescriptor;
062import org.opends.guitools.controlpanel.datamodel.BackupDescriptor;
063import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
064import org.opends.guitools.controlpanel.datamodel.ScheduleType;
065import org.opends.guitools.controlpanel.datamodel.ServerDescriptor;
066import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent;
067import org.opends.guitools.controlpanel.task.Task;
068import org.opends.guitools.controlpanel.ui.components.ScheduleSummaryPanel;
069import org.opends.guitools.controlpanel.util.BackgroundTask;
070import org.opends.guitools.controlpanel.util.Utilities;
071import org.opends.server.tools.BackUpDB;
072import org.opends.server.types.BackupDirectory;
073import org.opends.server.types.BackupInfo;
074import org.opends.server.util.ServerConstants;
075
076/**
077 * The panel that appears when the user clicks on 'Backup...'.
078 *
079 */
080public class BackupPanel extends BackupListPanel
081{
082  private static final long serialVersionUID = -1626301350756394814L;
083  private JComboBox backends;
084  private JCheckBox allBackends;
085  private JTextField backupID;
086  private JTextField parentBackupID;
087  private JRadioButton fullBackup;
088  private JCheckBox incrementalParent;
089  private JRadioButton incrementalBackup;
090  private JCheckBox compressData;
091  private JCheckBox encryptData;
092  private JCheckBox generateMessageDigest;
093  private JCheckBox signMessageDigest;
094
095  private JLabel lBackend;
096  private JLabel lNoBackendsFound;
097  private JLabel lBackupID;
098  private JLabel lParentID;
099  private JLabel lBackupType;
100  private JLabel lBackupOptions;
101
102  private ChangeListener changeListener;
103
104  private boolean backupIDInitialized;
105
106  private ScheduleSummaryPanel schedulePanel;
107
108  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
109
110  /**
111   * Default constructor.
112   *
113   */
114  public BackupPanel()
115  {
116    super();
117    createLayout();
118  }
119
120  /** {@inheritDoc} */
121  public LocalizableMessage getTitle()
122  {
123    return INFO_CTRL_PANEL_BACKUP_TITLE.get();
124  }
125
126  /** {@inheritDoc} */
127  public Component getPreferredFocusComponent()
128  {
129    return backupID;
130  }
131
132  /** {@inheritDoc} */
133  protected void verifyBackupClicked()
134  {
135    // Nothing to do: the button is not visible.
136  }
137
138  /**
139   * Creates the layout of the panel (but the contents are not populated here).
140   *
141   */
142  private void createLayout()
143  {
144    GridBagConstraints gbc = new GridBagConstraints();
145    gbc.anchor = GridBagConstraints.WEST;
146    gbc.gridx = 0;
147    gbc.gridy = 0;
148    gbc.gridwidth = 3;
149    addErrorPane(gbc);
150
151    gbc.weightx = 0.0;
152    gbc.gridy ++;
153    gbc.gridwidth = 1;
154    gbc.fill = GridBagConstraints.NONE;
155    lBackend = Utilities.createPrimaryLabel(
156        INFO_CTRL_PANEL_BACKEND_LABEL.get());
157    add(lBackend, gbc);
158    gbc.insets.left = 10;
159    gbc.gridx = 1;
160    gbc.gridwidth = 2;
161    JPanel auxPanel = new JPanel(new GridBagLayout());
162    add(auxPanel, gbc);
163    auxPanel.setOpaque(false);
164    GridBagConstraints gbc2 = new GridBagConstraints();
165    backends = Utilities.createComboBox();
166    backends.setModel(new DefaultComboBoxModel(new String[]{}));
167    auxPanel.add(backends, gbc2);
168    lNoBackendsFound = Utilities.createDefaultLabel(
169        INFO_CTRL_PANEL_NO_BACKENDS_FOUND_LABEL.get());
170    add(lNoBackendsFound, gbc);
171    lNoBackendsFound.setVisible(false);
172    gbc2.insets.left = 10;
173    allBackends = Utilities.createCheckBox(
174        INFO_CTRL_PANEL_BACKUP_ALL_BACKENDS_LABEL.get());
175    auxPanel.add(allBackends, gbc2);
176
177    gbc.insets.top = 10;
178    gbc.gridx = 0;
179    gbc.gridy ++;
180    gbc.insets.left = 0;
181    gbc.gridwidth = 1;
182    lBackupType = Utilities.createPrimaryLabel(
183        INFO_CTRL_PANEL_BACKUP_TYPE_LABEL.get());
184    add(lBackupType, gbc);
185    gbc.insets.left = 10;
186    gbc.gridx = 1;
187    gbc.gridwidth = 2;
188    fullBackup = Utilities.createRadioButton(
189        INFO_CTRL_PANEL_FULL_BACKUP_LABEL.get());
190    add(fullBackup, gbc);
191
192    gbc.gridy ++;
193    gbc.insets.top = 5;
194    incrementalBackup = Utilities.createRadioButton(
195        INFO_CTRL_PANEL_INCREMENTAL_BACKUP_LABEL.get());
196    add(incrementalBackup, gbc);
197
198    gbc.gridy ++;
199    gbc.insets.left = 25;
200    incrementalParent = Utilities.createCheckBox(
201        INFO_CTRL_PANEL_INCREMENTAL_PARENT_LABEL.get());
202    add(incrementalParent, gbc);
203
204    ButtonGroup group = new ButtonGroup();
205    group.add(fullBackup);
206    group.add(incrementalBackup);
207    fullBackup.setSelected(true);
208
209    gbc.insets.top = 10;
210    gbc.gridx = 0;
211    gbc.gridy ++;
212    gbc.insets.left = 0;
213    gbc.gridwidth = 1;
214    lBackupID = Utilities.createPrimaryLabel(
215        INFO_CTRL_PANEL_BACKUP_ID_LABEL.get());
216    add(lBackupID, gbc);
217    backupID = Utilities.createMediumTextField();
218    gbc.weightx = 0.0;
219    gbc.gridx ++;
220    gbc.insets.left = 10;
221    gbc.fill = GridBagConstraints.NONE;
222    gbc.gridwidth = 2;
223    add(backupID, gbc);
224
225    gbc.insets.top = 10;
226    gbc.gridx = 0;
227    gbc.gridy ++;
228    super.createLayout(gbc);
229
230    verifyBackup.setVisible(false);
231    lAvailableBackups.setText(
232        INFO_CTRL_PANEL_AVAILABLE_PARENT_BACKUPS_LABEL.get().toString());
233    gbc.gridx = 0;
234    gbc.gridy ++;
235    gbc.insets.left = 0;
236    gbc.insets.top = 10;
237    gbc.gridwidth = 1;
238    gbc.anchor = GridBagConstraints.WEST;
239    lParentID = Utilities.createPrimaryLabel(
240        INFO_CTRL_PANEL_PARENT_BACKUP_ID_LABEL.get());
241    add(lParentID, gbc);
242    parentBackupID = Utilities.createMediumTextField();
243    gbc.weightx = 0.0;
244    gbc.gridx ++;
245    gbc.insets.left = 10;
246    gbc.fill = GridBagConstraints.NONE;
247    gbc.gridwidth = 2;
248    add(parentBackupID, gbc);
249
250    gbc.gridy ++;
251    gbc.gridx = 0;
252    gbc.gridwidth = 1;
253    gbc.insets.left = 0;
254    lBackupOptions = Utilities.createPrimaryLabel(
255        INFO_CTRL_PANEL_BACKUP_OPTIONS_LABEL.get());
256    add(lBackupOptions, gbc);
257
258    schedulePanel = new ScheduleSummaryPanel(
259        INFO_CTRL_PANEL_BACKUP_TASK_NAME.get().toString());
260    schedulePanel.setSchedule(ScheduleType.createLaunchNow());
261
262    gbc.insets.left = 10;
263    gbc.gridx = 1;
264    gbc.gridwidth = 2;
265    add(schedulePanel, gbc);
266
267    compressData = Utilities.createCheckBox(
268        INFO_CTRL_PANEL_COMPRESS_DATA_LABEL.get());
269    compressData.setSelected(false);
270
271    gbc.gridy ++;
272    gbc.insets.top = 5;
273    add(compressData, gbc);
274
275    encryptData = Utilities.createCheckBox(
276        INFO_CTRL_PANEL_ENCRYPT_DATA_LABEL.get());
277
278    gbc.gridy ++;
279    add(encryptData, gbc);
280    encryptData.setSelected(false);
281    generateMessageDigest = Utilities.createCheckBox(
282        INFO_CTRL_PANEL_GENERATE_MESSAGE_DIGEST_LABEL.get());
283
284    gbc.gridy ++;
285    add(generateMessageDigest, gbc);
286
287    signMessageDigest = Utilities.createCheckBox(
288        INFO_CTRL_PANEL_SIGN_MESSAGE_DIGEST_HASH_LABEL.get());
289    gbc.insets.left = 30;
290    gbc.gridy ++;
291    add(signMessageDigest, gbc);
292    generateMessageDigest.setSelected(false);
293
294    changeListener = new ChangeListener()
295    {
296      /** {@inheritDoc} */
297      public void stateChanged(ChangeEvent ev)
298      {
299        backends.setEnabled(!allBackends.isSelected());
300        signMessageDigest.setEnabled(generateMessageDigest.isSelected());
301        incrementalParent.setEnabled(incrementalBackup.isSelected());
302        boolean enable = isIncrementalWithParent();
303        refreshList.setEnabled(enable);
304        tableScroll.setEnabled(enable);
305        backupList.setEnabled(enable);
306        lAvailableBackups.setEnabled(enable);
307        lRefreshingList.setEnabled(enable);
308        lParentID.setEnabled(enable);
309        parentBackupID.setEnabled(enable);
310        verifyBackup.setEnabled(enable && getSelectedBackup() != null);
311      }
312    };
313    incrementalBackup.addChangeListener(changeListener);
314    incrementalParent.addChangeListener(changeListener);
315    generateMessageDigest.addChangeListener(changeListener);
316    allBackends.addChangeListener(changeListener);
317    changeListener.stateChanged(null);
318
319    addBottomGlue(gbc);
320  }
321
322  /**
323   * Check status of incremental backup radio/checkbox
324   *
325   * @return boolean true if both incremental and parent base ID
326   *                  are selected
327   */
328  private boolean isIncrementalWithParent()
329  {
330    return incrementalParent.isSelected() &&
331            incrementalBackup.isSelected();
332  }
333
334  /** {@inheritDoc} */
335  public void configurationChanged(ConfigurationChangeEvent ev)
336  {
337    final ServerDescriptor desc = ev.getNewDescriptor();
338    updateSimpleBackendComboBoxModel(backends, lNoBackendsFound, desc);
339    SwingUtilities.invokeLater(new Runnable()
340    {
341      /** {@inheritDoc} */
342      public void run()
343      {
344        allBackends.setVisible(backends.getModel().getSize() > 0);
345        lParentID.setVisible(!desc.isLocal());
346        parentBackupID.setVisible(!desc.isLocal());
347        if (desc.isLocal())
348        {
349          lPath.setText(INFO_CTRL_PANEL_BACKUP_PATH_LABEL.get().toString());
350        }
351        else
352        {
353          lPath.setText(
354              INFO_CTRL_PANEL_PARENT_BACKUP_PATH_LABEL.get().toString());
355        }
356      }
357    });
358    super.configurationChanged(ev);
359    updateErrorPaneAndOKButtonIfAuthRequired(desc,
360        isLocal() ? INFO_CTRL_PANEL_AUTHENTICATION_REQUIRED_FOR_BACKUP.get() :
361      INFO_CTRL_PANEL_CANNOT_CONNECT_TO_REMOTE_DETAILS.get(desc.getHostname()));
362  }
363
364  /** {@inheritDoc} */
365  public void okClicked()
366  {
367    setPrimaryValid(lBackend);
368    setPrimaryValid(lPath);
369    setPrimaryValid(lAvailableBackups);
370    setPrimaryValid(lParentID);
371    setPrimaryValid(lBackupOptions);
372    backupIDInitialized = false;
373
374    final LinkedHashSet<LocalizableMessage> errors = new LinkedHashSet<>();
375
376    if (!allBackends.isSelected())
377    {
378      String backendName = (String)backends.getSelectedItem();
379      if (backendName == null)
380      {
381        errors.add(ERR_CTRL_PANEL_NO_BACKENDS_SELECTED.get());
382        setPrimaryInvalid(lBackend);
383      }
384    }
385    else
386    {
387      if (backends.getModel().getSize() == 0)
388      {
389        errors.add(ERR_CTRL_PANEL_NO_BACKENDS_AVAILABLE.get());
390        setPrimaryInvalid(lBackend);
391      }
392    }
393
394    String parentPath = parentDirectory.getText();
395    if (parentPath == null || parentPath.trim().equals(""))
396    {
397      errors.add(ERR_CTRL_PANEL_NO_BACKUP_PATH_PROVIDED.get());
398      setPrimaryInvalid(lPath);
399    }
400    else if (isLocal())
401    {
402      File f = new File(parentPath);
403      if (f.isFile())
404      {
405        errors.add(ERR_CTRL_PANEL_BACKUP_PATH_IS_A_FILE.get(parentPath));
406        setPrimaryInvalid(lPath);
407      }
408      else if (!f.exists())
409      {
410        errors.add(ERR_CTRL_PANEL_BACKUP_PATH_DOES_NOT_EXIST.get(parentPath));
411        setPrimaryInvalid(lPath);
412      }
413    }
414    String dir = backupID.getText();
415    if (dir == null || dir.trim().equals(""))
416    {
417      errors.add(ERR_CTRL_PANEL_NO_BACKUP_ID_PROVIDED.get());
418      setPrimaryInvalid(lBackupID);
419    }
420
421    if (errors.isEmpty() && isLocal())
422    {
423      File f = new File(parentPath, dir);
424      if (f.isFile())
425      {
426        errors.add(ERR_CTRL_PANEL_BACKUP_PATH_EXISTS.get(
427            f.getAbsolutePath()));
428        setPrimaryInvalid(lPath);
429      }
430    }
431
432    if (isIncrementalWithParent())
433    {
434      if (isLocal())
435      {
436        boolean selected = backupList.isVisible() && getSelectedBackup() != null;
437        if (!selected)
438        {
439          errors.add(ERR_CTRL_PANEL_NO_PARENT_BACKUP_SELECTED.get());
440          setPrimaryInvalid(lAvailableBackups);
441        }
442      }
443      else
444      {
445        String parentID = parentBackupID.getText();
446        if (parentID == null || parentID.trim().equals(""))
447        {
448          errors.add(ERR_CTRL_PANEL_NO_PARENT_BACKUP_ID_PROVIDED.get());
449          setPrimaryInvalid(lParentID);
450        }
451      }
452    }
453
454    addScheduleErrors(getSchedule(), errors, lBackupOptions);
455
456    // Check that there is not a backup with the provided ID
457    final JComponent[] components =
458    {
459        backends, allBackends, fullBackup, incrementalBackup, parentDirectory,
460        browse, backupList, refreshList, compressData, encryptData,
461        generateMessageDigest, signMessageDigest, incrementalParent
462    };
463    setEnabledOK(false);
464    setEnabledCancel(false);
465    for (int i=0; i<components.length; i++)
466    {
467      components[i].setEnabled(false);
468    }
469    final String id = backupID.getText();
470    final String path = parentDirectory.getText();
471    BackgroundTask<Void> worker = new BackgroundTask<Void>()
472    {
473      /** {@inheritDoc} */
474      public Void processBackgroundTask() throws Throwable
475      {
476        // Open the backup directory and make sure it is valid.
477        LinkedHashSet<BackupInfo> backups = new LinkedHashSet<>();
478        try
479        {
480          BackupDirectory backupDir =
481            BackupDirectory.readBackupDirectoryDescriptor(path);
482          backups.addAll(backupDir.getBackups().values());
483        }
484        catch (Throwable t)
485        {
486          // Check the subdirectories
487          File f = new File(path);
488
489          if (f.isDirectory())
490          {
491            File[] children = f.listFiles();
492            for (int i=0; i<children.length; i++)
493            {
494              if (children[i].isDirectory())
495              {
496                try
497                {
498                  BackupDirectory backupDir =
499                    BackupDirectory.readBackupDirectoryDescriptor(
500                        children[i].getAbsolutePath());
501
502                  backups.addAll(backupDir.getBackups().values());
503                }
504                catch (Throwable t2)
505                {
506                  if (!children[i].getName().equals("tasks"))
507                  {
508                    logger.warn(LocalizableMessage.raw("Error searching backup: "+t2, t2));
509                  }
510                }
511              }
512            }
513          }
514        }
515        for (BackupInfo backup : backups)
516        {
517          if (backup.getBackupID().equalsIgnoreCase(id))
518          {
519            errors.add(ERR_CTRL_PANEL_BACKUP_ID_ALREADY_EXIST.get(id, path));
520            SwingUtilities.invokeLater(new Runnable()
521            {
522              /** {@inheritDoc} */
523              public void run()
524              {
525                setPrimaryInvalid(lBackupID);
526              }
527            });
528            break;
529          }
530        }
531        return null;
532      }
533      /** {@inheritDoc} */
534      public void backgroundTaskCompleted(Void returnValue,
535          Throwable t)
536      {
537        for (int i=0; i<components.length; i++)
538        {
539          components[i].setEnabled(true);
540        }
541        setEnabledOK(true);
542        setEnabledCancel(true);
543        changeListener.stateChanged(null);
544        if (errors.isEmpty())
545        {
546          ProgressDialog progressDialog = new ProgressDialog(
547              Utilities.createFrame(),
548              Utilities.getParentDialog(BackupPanel.this),
549              getTitle(), getInfo());
550          BackupTask newTask = new BackupTask(getInfo(), progressDialog);
551          for (Task task : getInfo().getTasks())
552          {
553            task.canLaunch(newTask, errors);
554          }
555          if (errors.isEmpty())
556          {
557            LocalizableMessage initMsg;
558            if (allBackends.isSelected())
559            {
560              initMsg = INFO_CTRL_PANEL_RUN_BACKUP_ALL_BACKENDS.get();
561            }
562            else
563            {
564              initMsg = INFO_CTRL_PANEL_RUN_BACKUP_SUMMARY.get(
565                  backends.getSelectedItem());
566            }
567            launchOperation(newTask,
568                initMsg,
569                INFO_CTRL_PANEL_RUN_BACKUP_SUCCESSFUL_SUMMARY.get(),
570                INFO_CTRL_PANEL_RUN_BACKUP_SUCCESSFUL_DETAILS.get(),
571                ERR_CTRL_PANEL_RUN_BACKUP_ERROR_SUMMARY.get(),
572                null,
573                ERR_CTRL_PANEL_RUN_BACKUP_ERROR_DETAILS,
574                progressDialog);
575            progressDialog.setVisible(true);
576            Utilities.getParentDialog(BackupPanel.this).setVisible(false);
577          }
578        }
579        if (!errors.isEmpty())
580        {
581          displayErrorDialog(errors);
582        }
583      }
584    };
585    if (errors.isEmpty())
586    {
587      worker.startBackgroundTask();
588    }
589    else
590    {
591      worker.backgroundTaskCompleted(null, null);
592    }
593  }
594
595  private ScheduleType getSchedule()
596  {
597    return schedulePanel.getSchedule();
598  }
599
600  /** {@inheritDoc} */
601  public void cancelClicked()
602  {
603    setPrimaryValid(lBackend);
604    setPrimaryValid(lPath);
605    setPrimaryValid(lAvailableBackups);
606    setPrimaryValid(lBackupOptions);
607
608    super.cancelClicked();
609  }
610
611  /** {@inheritDoc} */
612  public void toBeDisplayed(boolean visible)
613  {
614    super.toBeDisplayed(visible);
615    if (visible && !backupIDInitialized)
616    {
617      initializeBackupID();
618    }
619    if (!visible)
620    {
621      backupIDInitialized = false;
622    }
623  }
624
625  /**
626   * Initialize the backup ID field with a value.
627   *
628   */
629  private void initializeBackupID()
630  {
631    SimpleDateFormat dateFormat = new SimpleDateFormat(
632        ServerConstants.DATE_FORMAT_COMPACT_LOCAL_TIME);
633    final String id = dateFormat.format(new Date());
634    backupID.setText(id);
635  }
636
637  /**
638   * Class that launches the backup.
639   *
640   */
641  protected class BackupTask extends Task
642  {
643    private Set<String> backendSet;
644    private String dir;
645    /**
646     * The constructor of the task.
647     * @param info the control panel info.
648     * @param dlg the progress dialog that shows the progress of the task.
649     */
650    public BackupTask(ControlPanelInfo info, ProgressDialog dlg)
651    {
652      super(info, dlg);
653      backendSet = new HashSet<>();
654      if (!allBackends.isSelected())
655      {
656        backendSet.add((String)backends.getSelectedItem());
657      }
658      else
659      {
660        for (BackendDescriptor backend :
661          info.getServerDescriptor().getBackends())
662        {
663          if (!backend.isConfigBackend())
664          {
665            backendSet.add(backend.getBackendID());
666          }
667        }
668      }
669      if (isIncrementalWithParent())
670      {
671        if (isLocal())
672        {
673          BackupDescriptor backup = getSelectedBackup();
674          dir = backup.getPath().getAbsolutePath();
675        }
676        else
677        {
678          dir = parentDirectory.getText();
679        }
680      }
681      else
682      {
683        dir = parentDirectory.getText();
684      }
685    }
686
687    /** {@inheritDoc} */
688    public Type getType()
689    {
690      return Type.BACKUP;
691    }
692
693    /** {@inheritDoc} */
694    public LocalizableMessage getTaskDescription()
695    {
696      return INFO_CTRL_PANEL_BACKUP_TASK_DESCRIPTION.get(
697      Utilities.getStringFromCollection(backendSet, ", "), dir);
698    }
699
700    /** {@inheritDoc} */
701    public boolean canLaunch(Task taskToBeLaunched,
702        Collection<LocalizableMessage> incompatibilityReasons)
703    {
704      boolean canLaunch = true;
705      if (state == State.RUNNING && runningOnSameServer(taskToBeLaunched))
706      {
707        // All the operations are incompatible if they apply to this backend.
708        Set<String> backends = new TreeSet<>(taskToBeLaunched.getBackends());
709        backends.retainAll(getBackends());
710        if (!backends.isEmpty())
711        {
712          incompatibilityReasons.add(getIncompatibilityMessage(this, taskToBeLaunched));
713          canLaunch = false;
714        }
715      }
716      return canLaunch;
717    }
718
719    /** {@inheritDoc} */
720    public void runTask()
721    {
722      state = State.RUNNING;
723      lastException = null;
724      try
725      {
726        ArrayList<String> arguments = getCommandLineArguments();
727
728        String[] args = new String[arguments.size()];
729
730        arguments.toArray(args);
731        if (isServerRunning())
732        {
733          returnCode = BackUpDB.mainBackUpDB(args, false, outPrintStream,
734              errorPrintStream);
735        }
736        else
737        {
738          returnCode = executeCommandLine(getCommandLinePath(), args);
739        }
740        if (returnCode != 0)
741        {
742          state = State.FINISHED_WITH_ERROR;
743        }
744        else
745        {
746          getInfo().backupCreated(
747              new BackupDescriptor(
748                  new File(parentDirectory.getText()),
749                  new Date(),
750                  fullBackup.isSelected() ? BackupDescriptor.Type.FULL :
751                    BackupDescriptor.Type.INCREMENTAL,
752                  backupID.getText()));
753          state = State.FINISHED_SUCCESSFULLY;
754        }
755      }
756      catch (Throwable t)
757      {
758        lastException = t;
759        state = State.FINISHED_WITH_ERROR;
760      }
761    }
762
763    /** {@inheritDoc} */
764    public Set<String> getBackends()
765    {
766      return backendSet;
767    }
768
769    /** {@inheritDoc} */
770    protected ArrayList<String> getCommandLineArguments()
771    {
772      ArrayList<String> args = new ArrayList<>();
773
774      args.add("--backupDirectory");
775      args.add(dir);
776
777      args.add("--backupID");
778      args.add(backupID.getText());
779
780      if (allBackends.isSelected())
781      {
782        args.add("--backUpAll");
783      }
784      else
785      {
786        args.add("--backendID");
787        args.add((String)backends.getSelectedItem());
788      }
789
790      if (incrementalBackup.isSelected())
791      {
792        args.add("--incremental");
793        if(incrementalParent.isSelected())
794        {
795          if (isLocal())
796          {
797            BackupDescriptor backup = getSelectedBackup();
798            args.add("--incrementalBaseID");
799            args.add(backup.getID());
800          }
801          else
802          {
803            args.add("--incrementalBaseID");
804            args.add(parentBackupID.getText());
805          }
806        }
807      }
808
809
810      if (compressData.isSelected())
811      {
812        args.add("--compress");
813      }
814
815      if (encryptData.isSelected())
816      {
817        args.add("--encrypt");
818      }
819
820      if (generateMessageDigest.isSelected())
821      {
822        args.add("--hash");
823        if (signMessageDigest.isSelected())
824        {
825          args.add("--signHash");
826        }
827      }
828
829      args.addAll(getConnectionCommandLineArguments());
830
831      args.addAll(getScheduleArgs(getSchedule()));
832
833      if (isServerRunning())
834      {
835        args.addAll(getConfigCommandLineArguments());
836      }
837
838      args.add(getNoPropertiesFileArgument());
839
840      return args;
841    }
842
843    /** {@inheritDoc} */
844    protected String getCommandLinePath()
845    {
846      return getCommandLinePath("backup");
847    }
848  }
849}