-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial creation of h2 backup plugin project
- Loading branch information
0 parents
commit 27c4e52
Showing
11 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
target/ | ||
.idea/ | ||
project/project/ | ||
project/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# gitbucket-h2-backup-plugin | ||
|
||
This plugin enhances [takezoe/gitbucket](https://github.com/takezoe/gitbucket) by offering a way to backup/dump the h2 database of gitbucket. | ||
|
||
It originates from [pull request #845](takezoe/gitbucket#845) and can be used to adress database backup described in [gitbucket backup documentation](https://github.com/takezoe/gitbucket/wiki/Backup) | ||
|
||
## Features | ||
|
||
### H2 Backup | ||
|
||
This plugin allows to backup the underlying H2 database used by default by gitbucket. | ||
|
||
## Usage | ||
|
||
The plugin provides 2 ways to backup the H2 database: | ||
|
||
- via an administration page and a backup button | ||
- via an HTTP call to http://YOUR_GITBUCKET/database/backup | ||
|
||
In current version database backup file is written to `GITBUCKET_HOME/.gitbucket/gitbucket-database-backup.zip`. | ||
|
||
## Release Notes | ||
|
||
### 1.0 | ||
|
||
- introduce gitbucket-h2-backup-plugin | ||
- allows to backup h2 database via a live dump |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version = 0.13.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import sbt._ | ||
import Keys._ | ||
import play.twirl.sbt.SbtTwirl | ||
import play.twirl.sbt.Import.TwirlKeys._ | ||
|
||
object MyBuild extends Build { | ||
|
||
val Organization = "fr.brouillard.gitbucket" | ||
val Name = "gitbucket-h2-backup-plugin" | ||
val Version = "1.0" | ||
val ScalaVersion = "2.11.6" | ||
|
||
lazy val project = Project ( | ||
"gitbucket-h2-backup-plugin", | ||
file(".") | ||
) | ||
.settings( | ||
sourcesInBase := false, | ||
organization := Organization, | ||
name := Name, | ||
version := Version, | ||
scalaVersion := ScalaVersion, | ||
scalacOptions := Seq("-deprecation", "-language:postfixOps"), | ||
resolvers ++= Seq( | ||
"amateras-repo" at "http://amateras.sourceforge.jp/mvn/" | ||
), | ||
libraryDependencies ++= Seq( | ||
"gitbucket" % "gitbucket-assembly" % "3.5.0" % "provided", | ||
"com.typesafe.play" %% "twirl-compiler" % "1.0.4" % "provided", | ||
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided" | ||
), | ||
javacOptions in compile ++= Seq("-target", "7", "-source", "7") | ||
).enablePlugins(SbtTwirl) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
logLevel := Level.Warn | ||
|
||
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.0.2") |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
set SCRIPT_DIR=%~dp0 | ||
java -Dsbt.log.noformat=true -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -jar "%SCRIPT_DIR%\sbt-launch-0.13.5.jar" %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
java -Dsbt.log.noformat=true -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -jar `dirname $0`/sbt-launch-0.13.5.jar "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import javax.servlet.ServletContext | ||
|
||
import fr.brouillard.gitbucket.h2.controller.H2BackupController | ||
import gitbucket.core.plugin.PluginRegistry | ||
import gitbucket.core.service.SystemSettingsService.SystemSettings | ||
import gitbucket.core.util.Version | ||
|
||
class Plugin extends gitbucket.core.plugin.Plugin { | ||
override val pluginId: String = "h2-backup" | ||
|
||
override val pluginName: String = "H2 Database Backup Plugin" | ||
|
||
override val description: String = "Allows to export h2 database of gitbucket" | ||
|
||
override val versions: List[Version] = List( | ||
Version(1, 0) | ||
) | ||
|
||
override def javaScripts(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[(String, String)] = { | ||
// Add Snippet link to the header | ||
val path = settings.baseUrl.getOrElse(context.getContextPath) | ||
Seq( | ||
".*/admin/h2backup" -> s""" | ||
|$$('#system-admin-menu-container>li:last').after( | ||
| $$('<li class="active"><a href="${path}/admin/h2backup">H2 Backup</a></li>') | ||
|); | ||
""".stripMargin, | ||
".*/admin/(?!h2backup).*" -> s""" | ||
|$$('#system-admin-menu-container>li:last').after( | ||
| $$('<li><a href="${path}/admin/h2backup">H2 Backup</a></li>') | ||
|); | ||
""".stripMargin | ||
) | ||
} | ||
|
||
override val controllers = Seq( | ||
"/admin/h2backup" -> new H2BackupController() | ||
, "/database/backup" -> new H2BackupController() | ||
) | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/scala/fr/brouillard/gitbucket/h2/controller/H2BackupController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package fr.brouillard.gitbucket.h2.controller | ||
|
||
import java.io.File | ||
|
||
import gitbucket.core.controller.ControllerBase | ||
import gitbucket.core.servlet.Database | ||
import gitbucket.core.util.Directory._ | ||
import fr.brouillard.gitbucket.h2._ | ||
import org.scalatra.Ok | ||
import org.slf4j.LoggerFactory | ||
|
||
class H2BackupController extends ControllerBase { | ||
private val logger = LoggerFactory.getLogger(classOf[H2BackupController]) | ||
|
||
def exportDatabase: Unit = { | ||
val session = Database.getSession(request) | ||
val conn = session.conn | ||
val exportFile = new File(GitBucketHome, "gitbucket-database-backup.zip") | ||
|
||
logger.info("exporting database to {}", exportFile) | ||
|
||
conn.prepareStatement("BACKUP TO '" + exportFile + "'").execute(); | ||
} | ||
|
||
get("/admin/h2backup") { | ||
html.export(flash.get("info")); | ||
} | ||
|
||
get("/database/backup") { | ||
exportDatabase | ||
Ok("done") | ||
} | ||
|
||
post("/database/backup") { | ||
exportDatabase | ||
flash += "info" -> "H2 Database has been exported." | ||
redirect("/admin/h2backup") | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/twirl/fr/brouillard/gitbucket/h2/export.scala.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
@(info: Option[Any])(implicit context: gitbucket.core.controller.Context) | ||
@import context._ | ||
@import gitbucket.core.html.main | ||
@import gitbucket.core.admin.html.menu | ||
@import gitbucket.core.helper.html.information | ||
@import gitbucket.core.view.helpers._ | ||
@import gitbucket.core.util.Directory._ | ||
@main("H2 Backup"){ | ||
@menu("h2backup"){ | ||
@information(info) | ||
<form action="@path/database/backup" method="POST"> | ||
<div class="box"> | ||
<div class="box-header">Database export</div> | ||
<div class="box-content"> | ||
<label><span class="strong">Database export file:</span>@GitBucketHome/gitbucket-database-backup.zip</label> | ||
<p class="muted"> | ||
Allows to export the database content. The same action can be achieved via an HTTP GET call to @path/database/backup | ||
</p> | ||
|
||
<fieldset> | ||
<input type="submit" class="btn btn-primary" value="Export database"/> | ||
</fieldset> | ||
</div> | ||
</div> | ||
</form> | ||
} | ||
} | ||
|