From 3d05186cb246b3aa5db953df8e8861580ac57c25 Mon Sep 17 00:00:00 2001 From: Stefan Spieker Date: Sun, 7 Jul 2024 18:38:02 +0200 Subject: [PATCH 1/2] start respecting actual config-history settings --- pom.xml | 6 ++++ .../thinbackup/backup/HudsonBackup.java | 27 +++++++++++++++-- .../ThinBackupMgmtLink/restoreOptions.jelly | 4 +++ .../restoreOptions.properties | 1 + .../restoreOptions_de.properties | 3 +- .../help-backupConfigHistory.html | 2 +- .../help-backupConfigHistory_de.html | 2 +- .../help/help-restoreConfigHistory.html | 30 +++++++++++++++++++ .../help/help-restoreConfigHistory_de.html | 30 +++++++++++++++++++ 9 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 src/main/webapp/help/help-restoreConfigHistory.html create mode 100644 src/main/webapp/help/help-restoreConfigHistory_de.html diff --git a/pom.xml b/pom.xml index c4c8fda3..fd50777c 100644 --- a/pom.xml +++ b/pom.xml @@ -93,6 +93,12 @@ io.jenkins.plugins ionicons-api + + org.jenkins-ci.plugins + jobConfigHistory + 1229.v3039470161a_d + true + io.jenkins configuration-as-code diff --git a/src/main/java/org/jvnet/hudson/plugins/thinbackup/backup/HudsonBackup.java b/src/main/java/org/jvnet/hudson/plugins/thinbackup/backup/HudsonBackup.java index d7ac65a7..8ffaf561 100644 --- a/src/main/java/org/jvnet/hudson/plugins/thinbackup/backup/HudsonBackup.java +++ b/src/main/java/org/jvnet/hudson/plugins/thinbackup/backup/HudsonBackup.java @@ -18,11 +18,13 @@ import com.google.common.base.Throwables; import edu.umd.cs.findbugs.annotations.NonNull; +import hudson.Plugin; import hudson.PluginWrapper; import hudson.model.ItemGroup; import hudson.model.Job; import hudson.model.Run; import hudson.model.TopLevelItem; +import hudson.plugins.jobConfigHistory.JobConfigHistory; import hudson.util.RunList; import java.io.File; import java.io.FileNotFoundException; @@ -194,7 +196,15 @@ public void backup() throws IOException { } if (plugin.isBackupConfigHistory()) { - backupRootFolder(CONFIG_HISTORY_DIR_NAME); + final Plugin configHistoryPlugin = Jenkins.get().getPlugin("jobConfigHistory"); + if (configHistoryPlugin != null && configHistoryPlugin.getWrapper().isActive()) { + final JobConfigHistory descriptor = + (JobConfigHistory) Jenkins.get().getDescriptor(JobConfigHistory.class); + if (descriptor != null) { + final File configuredHistoryRootDir = descriptor.getConfiguredHistoryRootDir(); + backupConfigHistoryFolder(configuredHistoryRootDir.toString()); + } + } } if (plugin.isBackupPluginArchives()) { @@ -584,7 +594,7 @@ private void backupBuildArchive(final File buildSrcDir, final File buildDestDir) private void backupRootFolder(String folderName) throws IOException { try { - backupRootFolder(folderName, TrueFileFilter.INSTANCE); + backupRootFolder(folderName, TrueFileFilter.TRUE); } catch (IOException e) { if (plugin.isFailFast()) { throw e; @@ -595,6 +605,19 @@ private void backupRootFolder(String folderName) throws IOException { } } + private void backupConfigHistoryFolder(String folderName) throws IOException { + final File srcDirectory = new File(folderName); + if (srcDirectory.exists() && srcDirectory.isDirectory()) { + LOGGER.log(Level.FINE, "Backing up {0}...", folderName); + final File destDirectory = new File(backupDirectory.getAbsolutePath(), CONFIG_HISTORY_DIR_NAME); + IOFileFilter filter = + FileFilterUtils.and(TrueFileFilter.TRUE, getFileAgeDiffFilter(), getExcludedFilesFilter()); + filter = FileFilterUtils.or(filter, DirectoryFileFilter.DIRECTORY); + FileUtils.copyDirectory(srcDirectory, destDirectory, ExistsAndReadableFileFilter.wrapperFilter(filter)); + LOGGER.log(Level.FINE, "DONE backing up {0}.", folderName); + } + } + private void backupRootFolder(String folderName, IOFileFilter fileFilter) throws IOException { final File srcDirectory = new File(hudsonHome.getAbsolutePath(), folderName); if (srcDirectory.exists() && srcDirectory.isDirectory()) { diff --git a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupMgmtLink/restoreOptions.jelly b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupMgmtLink/restoreOptions.jelly index 15b228e5..dd15b55a 100644 --- a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupMgmtLink/restoreOptions.jelly +++ b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupMgmtLink/restoreOptions.jelly @@ -46,6 +46,10 @@ + + + + diff --git a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupMgmtLink/restoreOptions.properties b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupMgmtLink/restoreOptions.properties index a5b4f84a..17c3bb3d 100644 --- a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupMgmtLink/restoreOptions.properties +++ b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupMgmtLink/restoreOptions.properties @@ -3,3 +3,4 @@ restore_configuration = Restore Configuration restore_next_build_number = Restore next build number file (if found in backup) restore_options = Restore options restore_plugins = Restore plugins +restore_config_history = Restore config-history (if found in backup) diff --git a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupMgmtLink/restoreOptions_de.properties b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupMgmtLink/restoreOptions_de.properties index ff7c1264..f2685b53 100644 --- a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupMgmtLink/restoreOptions_de.properties +++ b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupMgmtLink/restoreOptions_de.properties @@ -1,5 +1,6 @@ restore_backup_from = Backup wiederherstellen von: restore_configuration = Restore Konfiguration -restore_next_build_number = Nächste Build Nummer Datein wiederherstellen (falls im Backup vorhanden) +restore_next_build_number = Nächste Build Nummer Dateien wiederherstellen (falls im Backup vorhanden) restore_options = Restore Optionen restore_plugins = Plugins wiederherstellen +restore_config_history = Config-history wiederherstellen (falls im Backup vorhanden) diff --git a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/help-backupConfigHistory.html b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/help-backupConfigHistory.html index 448b4fd8..0111c697 100644 --- a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/help-backupConfigHistory.html +++ b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/help-backupConfigHistory.html @@ -24,6 +24,6 @@

- If this option is enabled, the directory config-history will also be backed up. + If this option is enabled, the directory which is configured within the config-history plugin will also be backed up (only if plugin is installed).

diff --git a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/help-backupConfigHistory_de.html b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/help-backupConfigHistory_de.html index 452bc0f0..20afc913 100644 --- a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/help-backupConfigHistory_de.html +++ b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/help-backupConfigHistory_de.html @@ -24,6 +24,6 @@

- Falls diese Option aktiviert ist, wird das Verzeichnis config-history zum Backup hinzugefügt. + Falls diese Option aktiviert ist, wird das Verzeichnis, welches im config-history konfiguriert ist, zum Backup hinzugefügt (nur wenn das Plugin installiert ist).

diff --git a/src/main/webapp/help/help-restoreConfigHistory.html b/src/main/webapp/help/help-restoreConfigHistory.html new file mode 100644 index 00000000..739c56de --- /dev/null +++ b/src/main/webapp/help/help-restoreConfigHistory.html @@ -0,0 +1,30 @@ + + +
+

+ If this option is enabled, the config-history gets restored.
+ This will only work, if the config-history plugin is installed, otherwise it cannot read the config folder. +

+
diff --git a/src/main/webapp/help/help-restoreConfigHistory_de.html b/src/main/webapp/help/help-restoreConfigHistory_de.html new file mode 100644 index 00000000..0574186f --- /dev/null +++ b/src/main/webapp/help/help-restoreConfigHistory_de.html @@ -0,0 +1,30 @@ + + +
+

+ Falls diese Option aktiviert ist, wird die config-history aus dem Backup wiederhergestellt.
+ Es wird nur funktionieren, falls das config-history Plugin installiert ist, sonst kann der Konfigurationsordner nicht ausgelesen werden. +

+
From f9fedb9da6389215ed25aebf8545057bdc9ddbfc Mon Sep 17 00:00:00 2001 From: Stefan Spieker Date: Sun, 7 Jul 2024 18:41:19 +0200 Subject: [PATCH 2/2] fixed copyright --- src/main/webapp/help/help-restoreConfigHistory.html | 2 +- src/main/webapp/help/help-restoreConfigHistory_de.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/webapp/help/help-restoreConfigHistory.html b/src/main/webapp/help/help-restoreConfigHistory.html index 739c56de..5811b822 100644 --- a/src/main/webapp/help/help-restoreConfigHistory.html +++ b/src/main/webapp/help/help-restoreConfigHistory.html @@ -1,7 +1,7 @@