Permalink
Browse files

fix for JENKINS-13059: Backup userContent folder too

git-svn-id: https://svn.jenkins-ci.org/trunk/hudson/plugins/thinBackup@40550 71c3de6d-444a-0410-be80-ed276b4c234a
  • Loading branch information...
tofuatjava committed May 7, 2012
1 parent cccd328 commit b5c183abe7ea46db1290c2e77f0654361641519c
12 pom.xml
@@ -65,10 +65,20 @@
<url>www.borland.com</url>
</organization>
<repositories>
<repository>
<repository>
<id>m.g.o-public</id>
<url>http://maven.glassfish.org/content/groups/public/</url>
</repository>
<repository>
<id>maven.jenkins-ci.org</id>
<url>http://maven.jenkins-ci.org:8081/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
@@ -123,6 +123,7 @@ public void doSaveSettings(final StaplerRequest res, final StaplerResponse rsp,
@QueryParameter("cleanupDiff") final boolean cleanupDiff,
@QueryParameter("backupBuildResults") final boolean backupBuildResults,
@QueryParameter("backupBuildArchive") final boolean backupBuildArchive,
@QueryParameter("backupUserContents") final boolean backupUserContents,
@QueryParameter("backupNextBuildNumber") final boolean backupNextBuildNumber) throws IOException {
Hudson.getInstance().checkPermission(Hudson.ADMINISTER);

@@ -136,6 +137,7 @@ public void doSaveSettings(final StaplerRequest res, final StaplerResponse rsp,
plugin.setMoveOldBackupsToZipFile(moveOldBackupsToZipFile);
plugin.setBackupBuildResults(backupBuildResults);
plugin.setBackupBuildArchive(backupBuildArchive);
plugin.setBackupUserContents(backupUserContents);
plugin.setBackupNextBuildNumber(backupNextBuildNumber);
plugin.save();
LOGGER.finest("Saving backup settings done.");
@@ -75,7 +75,7 @@ protected void backupNow(final BackupType type) {
try {
backupPath = plugin.getExpandedBackupPath();

if (!StringUtils.isEmpty(backupPath)) {
if (StringUtils.isNotEmpty(backupPath)) {
if (plugin.isWaitForIdle()) {
LOGGER.fine("Wait until executors are idle to perform backup.");
Utils.waitUntilIdleAndSwitchToQuietMode(plugin.getForceQuietModeTimeout(), TimeUnit.MINUTES);
@@ -51,6 +51,7 @@
private boolean moveOldBackupsToZipFile = false;
private boolean backupBuildResults = true;
private boolean backupBuildArchive = false;
private boolean backupUserContents = false;
private boolean backupNextBuildNumber = false;

private static ThinBackupPluginImpl instance = null;
@@ -198,6 +199,14 @@ public void setExcludedFilesRegex(final String excludedFilesRegex) {
this.excludedFilesRegex = excludedFilesRegex;
}

public boolean isBackupUserContents() {
return this.backupUserContents;
}

public void setBackupUserContents(boolean backupUserContents) {
this.backupUserContents = backupUserContents;
}

public String getExcludedFilesRegex() {
return excludedFilesRegex;
}
@@ -321,12 +330,14 @@ public FormValidation doCheckExcludedFilesRegex(final StaplerRequest res, final

return FormValidation.ok();
}

public FormValidation doCheckWaitForIdle(final StaplerRequest res, final StaplerResponse rsp, @QueryParameter("value") final String waitForIdle) {

public FormValidation doCheckWaitForIdle(final StaplerRequest res, final StaplerResponse rsp,
@QueryParameter("value") final String waitForIdle) {
if (Boolean.parseBoolean(waitForIdle))
return FormValidation.ok();
else
return FormValidation.warning("This may or may not generate corrupt backups! Be aware that no data get changed during the backup process!");
return FormValidation
.warning("This may or may not generate corrupt backups! Be aware that no data get changed during the backup process!");
}

}
@@ -49,6 +49,7 @@
public static final String BUILDS_DIR_NAME = "builds";
public static final String JOBS_DIR_NAME = "jobs";
public static final String USERS_DIR_NAME = "users";
public static final String USERSCONTENTS_DIR_NAME = "userContent";
public static final String NEXT_BUILD_NUMBER_FILE_NAME = "nextBuildNumber";
public static final String ARCHIVE_DIR_NAME = "archive";
public static final String XML_FILE_EXTENSION = ".xml";
@@ -128,9 +129,12 @@ public void backup() throws IOException {

backupGlobalXmls();
backupJobs();
backupUsers();
backupRootFolder(USERS_DIR_NAME);
storePluginListIfChanged();

if (plugin.isBackupUserContents())
backupRootFolder(USERSCONTENTS_DIR_NAME);

new DirectoryCleaner().removeEmptyDirectories(backupDirectory);

if (backupType == BackupType.FULL) {
@@ -241,17 +245,16 @@ private void backupBuildArchive(final File buildSrcDir, final File buildDestDir)
}
}

private void backupUsers() throws IOException {
final File usersDirectory = new File(hudsonHome.getAbsolutePath(), USERS_DIR_NAME);
if (usersDirectory.exists() && usersDirectory.isDirectory()) {
LOGGER.fine("Backing up users specific configuration files...");
final File usersBackupDirectory = new File(backupDirectory.getAbsolutePath(), USERS_DIR_NAME);
IOFileFilter filter = FileFilterUtils.suffixFileFilter(XML_FILE_EXTENSION);
filter = FileFilterUtils.andFileFilter(filter, getFileAgeDiffFilter());
private void backupRootFolder(String folderName) throws IOException {
final File srcDirectory = new File(hudsonHome.getAbsolutePath(), folderName);
if (srcDirectory.exists() && srcDirectory.isDirectory()) {
LOGGER.fine(String.format("Backing up %s...", folderName));
final File destDirectory = new File(backupDirectory.getAbsolutePath(), folderName);
IOFileFilter filter = getFileAgeDiffFilter();
filter = FileFilterUtils.andFileFilter(filter, getExcludedFilesFilter());
filter = FileFilterUtils.orFileFilter(filter, DirectoryFileFilter.DIRECTORY);
FileUtils.copyDirectory(usersDirectory, usersBackupDirectory, filter);
LOGGER.fine("DONE backing up users specific configuration files.");
FileUtils.copyDirectory(srcDirectory, destDirectory, filter);
LOGGER.fine(String.format("DONE backing up %s.", folderName));
}
}

@@ -85,7 +85,7 @@ public static void waitUntilIdle() {

/**
* Waits until all executors are idle and switch jenkins to quiet mode. If it takes to long that all executors are
* idle because in the mean time other jobs are executed to timeout ensure that the quiet mode is forced.
* idle because in the mean time other jobs are executed the timeout ensure that the quiet mode is forced.
*
* @param timeout
* specifies when a quiet mode is forced. 0 = no timeout.

0 comments on commit b5c183a

Please sign in to comment.