From ffb2f48e079aa11a32146dc80c307a0f7774e6dd Mon Sep 17 00:00:00 2001 From: a1k0u Date: Thu, 15 Aug 2024 12:51:52 +0300 Subject: [PATCH] feat(config): move current backup set to zip file by flag --- .../thinbackup/ThinBackupPluginImpl.java | 12 ++++++ .../thinbackup/backup/HudsonBackup.java | 9 +++-- .../plugins/thinbackup/utils/Utils.java | 6 ++- .../ThinBackupPluginImpl/config.jelly | 10 +++-- .../ThinBackupPluginImpl/config.properties | 1 + .../ThinBackupPluginImpl/config_de.properties | 1 + .../help-moveCurrentBackupToZipFile.html | 36 ++++++++++++++++++ .../help-moveCurrentBackupToZipFile_de.html | 37 +++++++++++++++++++ .../thinbackup/TestJenkinsConfigAsCode.java | 1 + .../thinbackup/restore/TestRestore.java | 2 +- src/test/resources/configuration-as-code.yml | 1 + .../TestJenkinsWithOldConfig/thinBackup.xml | 1 + 12 files changed, 108 insertions(+), 9 deletions(-) create mode 100644 src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/help-moveCurrentBackupToZipFile.html create mode 100644 src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/help-moveCurrentBackupToZipFile_de.html diff --git a/src/main/java/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl.java b/src/main/java/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl.java index 30a8a3d..84e540c 100644 --- a/src/main/java/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl.java +++ b/src/main/java/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl.java @@ -57,6 +57,7 @@ public class ThinBackupPluginImpl extends GlobalConfiguration { private static final int VERY_HIGH_TIMEOUT = 12 * 60; private boolean cleanupDiff = false; private boolean moveOldBackupsToZipFile = false; + private boolean moveCurrentBackupToZipFile = false; private boolean backupBuildResults = true; private boolean backupBuildArchive = false; private boolean backupPluginArchives = false; @@ -100,6 +101,7 @@ public File getJenkinsHome() { @Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { + LOGGER.warning(json.toString()); try (BulkChange bc = new BulkChange(this)) { req.bindJSON(this, json); @@ -203,6 +205,16 @@ public boolean isMoveOldBackupsToZipFile() { return moveOldBackupsToZipFile; } + @DataBoundSetter + public void setMoveCurrentBackupToZipFile(final boolean moveCurrentBackupToZipFile) { + this.moveCurrentBackupToZipFile = moveCurrentBackupToZipFile; + save(); + } + + public boolean isMoveCurrentBackupToZipFile() { + return moveCurrentBackupToZipFile; + } + @DataBoundSetter public void setBackupBuildResults(final boolean backupBuildResults) { this.backupBuildResults = backupBuildResults; 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 d7ac65a..afdacdf 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 @@ -685,7 +685,8 @@ private void cleanupDiffs() throws IOException { private void moveOldBackupsToZipFile(final File currentBackup) { if (plugin.isMoveOldBackupsToZipFile()) { - final ZipperThread zipperThread = new ZipperThread(backupRoot, currentBackup); + final ZipperThread zipperThread = + new ZipperThread(backupRoot, currentBackup, plugin.isMoveCurrentBackupToZipFile()); zipperThread.start(); } } @@ -743,16 +744,18 @@ public static class ZipperThread extends Thread { private final File backupRoot; private final File currentBackup; + private final boolean moveCurrentBackupToZipFile; - public ZipperThread(final File backupRoot, final File currentBackup) { + public ZipperThread(final File backupRoot, final File currentBackup, final boolean moveCurrentBackupToZipFile) { this.backupRoot = backupRoot; this.currentBackup = currentBackup; + this.moveCurrentBackupToZipFile = moveCurrentBackupToZipFile; } @Override public void run() { LOGGER.fine("Starting zipper thread..."); - Utils.moveOldBackupsToZipFile(backupRoot, currentBackup); + Utils.moveOldBackupsToZipFile(backupRoot, currentBackup, moveCurrentBackupToZipFile); LOGGER.fine("DONE zipping."); } } diff --git a/src/main/java/org/jvnet/hudson/plugins/thinbackup/utils/Utils.java b/src/main/java/org/jvnet/hudson/plugins/thinbackup/utils/Utils.java index df35be2..9f8fce3 100644 --- a/src/main/java/org/jvnet/hudson/plugins/thinbackup/utils/Utils.java +++ b/src/main/java/org/jvnet/hudson/plugins/thinbackup/utils/Utils.java @@ -388,14 +388,16 @@ public static List getValidBackupSets(final File directory) { * @param currentBackup * specified which backup should be omitted from being moved. If null, all backups are moved to ZIP files. */ - public static void moveOldBackupsToZipFile(final File backupRoot, final File currentBackup) { + public static void moveOldBackupsToZipFile( + final File backupRoot, final File currentBackup, final boolean moveCurrentBackupToZipFile) { LOGGER.fine("Moving old backups to zip files..."); final List validBackupSets = Utils.getValidBackupSetsFromDirectories(backupRoot); int numberOfZippedBackupSets = 0; int numberOfMovedBackupSets = 0; for (final BackupSet backupSet : validBackupSets) { - if ((!backupSet.containsDirectory(currentBackup)) && (!backupSet.isInZipFile())) { + if ((!backupSet.containsDirectory(currentBackup) || moveCurrentBackupToZipFile) + && (!backupSet.isInZipFile())) { final File zippedBackupSet = backupSet.zipTo(backupRoot); ++numberOfZippedBackupSets; if (zippedBackupSet != null) { diff --git a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/config.jelly b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/config.jelly index d6ee62c..7897de7 100644 --- a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/config.jelly +++ b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/config.jelly @@ -85,9 +85,13 @@ - - - + + + + + diff --git a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/config.properties b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/config.properties index 6a32d58..d03b158 100644 --- a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/config.properties +++ b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/config.properties @@ -16,6 +16,7 @@ force_quite_minutes = Force Jenkins to quiet mode after specified minutes full_backup_schedule = Backup schedule for full backups max_backup_full = Max number of backup sets move = Move old backups to ZIP files +move_current = Move current backup to ZIP file thin_backup_configuration=ThinBackup Configuration wait_for_idle = Wait until Jenkins is idle to perform a backup fail_fast = Stop the backup as soon as an exception occurs in the file handling diff --git a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/config_de.properties b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/config_de.properties index 0dad341..fa3a847 100644 --- a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/config_de.properties +++ b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/config_de.properties @@ -16,6 +16,7 @@ force_quite_minutes = Zwinge Jenkins in den quiet mode nach x Minuten full_backup_schedule = Plan für vollständiges Backup max_backup_full = Maximale Anzahl an Backup Sätzen move = Alte Backups in ZIP Dateien verschieben +move_current = Aktuelle Backup in ZIP Datei verschieben thin_backup_configuration = ThinBackup Konfiguration wait_for_idle = Warte bis Jenkins idle ist um ein Backup durchzuführen fail_fast = Stoppe das Backup, sobald eine Exception in der Behandlung der Dateien auftritt diff --git a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/help-moveCurrentBackupToZipFile.html b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/help-moveCurrentBackupToZipFile.html new file mode 100644 index 0000000..0550c4d --- /dev/null +++ b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/help-moveCurrentBackupToZipFile.html @@ -0,0 +1,36 @@ + + +
+

+ If this is checked, then whenever a new full backup will be moved to ZIP file. + ZIP file will contain one backup set, i.e. one full backup and any diff backups referencing it. + The filename will identify the timeframe where the backups are included (i.e. the timestamp of the full backup and the timestamp of the latest diff backup). +

+

+ NOTE:
+ The setting "Max number of backup sets" applies to backup ZIP files created by thinBackup as well. + Also note that in case "Clean up differential backups" is checked it is performed before zipping is run (i.e. there will be no diff backups in the ZIP files). +

+
diff --git a/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/help-moveCurrentBackupToZipFile_de.html b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/help-moveCurrentBackupToZipFile_de.html new file mode 100644 index 0000000..4870264 --- /dev/null +++ b/src/main/resources/org/jvnet/hudson/plugins/thinbackup/ThinBackupPluginImpl/help-moveCurrentBackupToZipFile_de.html @@ -0,0 +1,37 @@ + + +
+

+ Falls diese Option aktiviert ist, werden jedem neuen Full Backup in ein ZIP file verschoben. + ZIP-Datei wird ein Vollbackup und alle differenziellen Backups die darauf referenzieren enthalten. + Der Dateiname wird das Zeitintervall identifizieren aus dem Backups enthalten sind. Also den Zeitstempel des Vollbackups und des letzten inkrementellen Backups. +

+

+ HINWEIS:
+ Die Einstellung Maximale Anzahl an Backup Sätzen gilt ebenfalls für ZIP-Dateien, die von thinBackup erstellt wurden. + Im Falle dass Differentielle Backups bereinigen aktiviert ist, werden, werden vor dem zippen die differenziellen Backups gelöscht. + Es werden also keine differenziellen Backups in der ZIP-Datei vorhanden sein. +

+
diff --git a/src/test/java/org/jvnet/hudson/plugins/thinbackup/TestJenkinsConfigAsCode.java b/src/test/java/org/jvnet/hudson/plugins/thinbackup/TestJenkinsConfigAsCode.java index d9baf8a..36a7144 100644 --- a/src/test/java/org/jvnet/hudson/plugins/thinbackup/TestJenkinsConfigAsCode.java +++ b/src/test/java/org/jvnet/hudson/plugins/thinbackup/TestJenkinsConfigAsCode.java @@ -35,6 +35,7 @@ public void should_support_configuration_as_code() { assertFalse(thinBackupPluginConfig.isCleanupDiff()); assertFalse(thinBackupPluginConfig.isMoveOldBackupsToZipFile()); + assertFalse(thinBackupPluginConfig.isMoveCurrentBackupToZipFile()); assertFalse(thinBackupPluginConfig.isBackupBuildArchive()); assertFalse(thinBackupPluginConfig.isBackupPluginArchives()); assertFalse(thinBackupPluginConfig.isBackupUserContents()); diff --git a/src/test/java/org/jvnet/hudson/plugins/thinbackup/restore/TestRestore.java b/src/test/java/org/jvnet/hudson/plugins/thinbackup/restore/TestRestore.java index 07665f3..90fc976 100644 --- a/src/test/java/org/jvnet/hudson/plugins/thinbackup/restore/TestRestore.java +++ b/src/test/java/org/jvnet/hudson/plugins/thinbackup/restore/TestRestore.java @@ -133,7 +133,7 @@ public void testRestoreFromZip() throws IOException, InterruptedException, Parse Assertions.assertEquals(1, backupsAsDates.size()); // create zips with older backups - Utils.moveOldBackupsToZipFile(backupDir, null); + Utils.moveOldBackupsToZipFile(backupDir, null, false); // check that backupset is present File[] files = backupDir.listFiles(); diff --git a/src/test/resources/configuration-as-code.yml b/src/test/resources/configuration-as-code.yml index 0816aaf..cec6980 100644 --- a/src/test/resources/configuration-as-code.yml +++ b/src/test/resources/configuration-as-code.yml @@ -17,5 +17,6 @@ unclassified: forceQuietModeTimeout: 120 fullBackupSchedule: "0 12 * * 1" moveOldBackupsToZipFile: false + moveCurrentBackupToZipFile: false nrMaxStoredFull: -1 waitForIdle: true diff --git a/src/test/resources/org/jvnet/hudson/plugins/thinbackup/TestJenkinsWithOldConfig/thinBackup.xml b/src/test/resources/org/jvnet/hudson/plugins/thinbackup/TestJenkinsWithOldConfig/thinBackup.xml index 31550e0..c4daed0 100644 --- a/src/test/resources/org/jvnet/hudson/plugins/thinbackup/TestJenkinsWithOldConfig/thinBackup.xml +++ b/src/test/resources/org/jvnet/hudson/plugins/thinbackup/TestJenkinsWithOldConfig/thinBackup.xml @@ -9,6 +9,7 @@ 1 false true + false true false false