Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start respecting actual config-history settings #144

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@
<groupId>io.jenkins.plugins</groupId>
<artifactId>ionicons-api</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jobConfigHistory</artifactId>
<version>1229.v3039470161a_d</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -194,7 +196,15 @@
}

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());

Check warning on line 205 in src/main/java/org/jvnet/hudson/plugins/thinbackup/backup/HudsonBackup.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 199-205 are not covered by tests
}
}
}

if (plugin.isBackupPluginArchives()) {
Expand Down Expand Up @@ -584,7 +594,7 @@

private void backupRootFolder(String folderName) throws IOException {
try {
backupRootFolder(folderName, TrueFileFilter.INSTANCE);
backupRootFolder(folderName, TrueFileFilter.TRUE);
} catch (IOException e) {
if (plugin.isFailFast()) {
throw e;
Expand All @@ -595,6 +605,19 @@
}
}

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);
}
}

Check warning on line 619 in src/main/java/org/jvnet/hudson/plugins/thinbackup/backup/HudsonBackup.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 609-619 are not covered by tests

private void backupRootFolder(String folderName, IOFileFilter fileFilter) throws IOException {
final File srcDirectory = new File(hudsonHome.getAbsolutePath(), folderName);
if (srcDirectory.exists() && srcDirectory.isDirectory()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
<f:checkbox name="restorePlugins"/>
</f:entry>

<f:entry title="${%restore_config_history}" help="/plugin/thinBackup/help/help-restoreConfigHistory.html">
<f:checkbox name="restoreConfigHistory"/>
</f:entry>

</f:section>

<f:bottomButtonBar>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@

<div>
<p>
If this option is enabled, the directory <em>config-history</em> 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).
</p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@

<div>
<p>
Falls diese Option aktiviert ist, wird das Verzeichnis <em>config-history</em> 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).
</p>
</div>
30 changes: 30 additions & 0 deletions src/main/webapp/help/help-restoreConfigHistory.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
The MIT License

Copyright (c) 2024 Stefan Spieker

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<div>
<p>
If this option is enabled, the config-history gets restored.<br/>
This will only work, if the config-history plugin is installed, otherwise it cannot read the config folder.
</p>
</div>
30 changes: 30 additions & 0 deletions src/main/webapp/help/help-restoreConfigHistory_de.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
The MIT License

Copyright (c) 2024 Stefan Spieker

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

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