Skip to content

Commit ef7539c

Browse files
authored
Merge pull request #25 from aadrian/patch_1
updates and use backup/ subdirectory
2 parents a66623e + e11f1a4 commit ef7539c

File tree

9 files changed

+27
-25
lines changed

9 files changed

+27
-25
lines changed

README.MD

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# gitbucket-h2-backup-plugin
22

3-
This plugin enhances [takezoe/gitbucket](https://github.com/takezoe/gitbucket) by offering a way to backup/dump the h2 database of gitbucket.
3+
This plugin enhances [GitBucket](https://github.com/gitbucket/gitbucket) by offering a way to backup/dump the H2 database of GitBucket.
44

5-
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)
5+
It originates from [pull request #845](takezoe/gitbucket#845) and can be used to address database backup described in [gitbucket backup documentation](https://github.com/takezoe/gitbucket/wiki/Backup)
66

77
## Features
88

99
### H2 Backup
1010

11-
This plugin allows to backup the underlying H2 database used by default by gitbucket.
11+
This plugin allows to backup the underlying H2 database used by default by GitBucket.
1212

1313
## Usage
1414

@@ -45,6 +45,7 @@ On success, you will receive a `HTTP 200` answer with a body containing `done: F
4545

4646
Plugin version | GitBucket version
4747
:--------------|:-----------------
48+
1.5.x | >= 4.12.y
4849
1.4.x | >= 4.10.y
4950
1.3.x | >= 4.3.y
5051
1.2.x | 4.x.y
@@ -64,6 +65,9 @@ sbt clean package
6465

6566
## Release Notes
6667

68+
### 1.5.0
69+
- compatibility with gitbucket 4.12.1 and scala 2.12
70+
6771
### 1.4.0
6872

6973
- compatibility with gitbucket 4.10, scala 2.12 [#20](https://github.com/gitbucket-plugins/gitbucket-h2-backup-plugin/issues/20)
@@ -94,7 +98,7 @@ sbt clean package
9498
In version 1.4.0, it is possible to secure the `database/backup` endpoint:
9599

96100
- launch gitbucket with System property _secure.backup_ set to true (for example `-Dsecure.backup=true` on the command line)
97-
- due to actual limitations of gibucket & plugins security, once the previous setting is activated,
101+
- due to actual limitations of gitbucket & plugins security, once the previous setting is activated,
98102
a call to `http://YOUR_GITBUCKET/database/backup` will be temporary redirected `http://YOUR_GITBUCKET/api/v3/plugins/database/backup`.
99103
You have to follow this temporary redirection.
100104
- if you call the endpoint using _httpie_, use the `--follow` parameter

build.sbt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
val Organization = "fr.brouillard.gitbucket"
22
val ProjectName = "gitbucket-h2-backup-plugin"
3-
val ProjectVersion = "1.4.0"
3+
val ProjectVersion = "1.5.0"
44

55
lazy val h2_backup_plugin = (project in file(".")).enablePlugins(SbtTwirl)
66

77
organization := Organization
88
name := ProjectName
99
version := ProjectVersion
10-
scalaVersion := "2.12.1"
10+
scalaVersion := "2.12.2"
1111

1212

1313
libraryDependencies ++= Seq(
14-
"io.github.gitbucket" %% "gitbucket" % "4.10.0" % "provided",
15-
"io.github.gitbucket" % "solidbase" % "1.0.0" % "provided",
14+
"io.github.gitbucket" %% "gitbucket" % "4.12.1" % "provided",
15+
"io.github.gitbucket" % "solidbase" % "1.0.2" % "provided",
1616
"com.typesafe.play" %% "twirl-compiler" % "1.3.0" % "provided",
1717
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided"
1818
)

project/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version = 0.13.12
1+
sbt.version = 0.13.15

sbt-launch-0.13.12.jar

-1.15 MB
Binary file not shown.

sbt.bat

-2
This file was deleted.

sbt.sh

-2
This file was deleted.

src/main/scala/Plugin.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ class Plugin extends gitbucket.core.plugin.Plugin {
99

1010
override val pluginName: String = "H2 Database Backup Plugin"
1111

12-
override val description: String = "Allows to export h2 database of gitbucket"
12+
override val description: String = "Allows to export the H2 database of GitBucket"
1313

1414
override val versions: List[Version] = List(
1515
new Version("1.0.0"),
1616
new Version("1.2.0"),
1717
new Version("1.3.0"),
18-
new Version("1.4.0")
18+
new Version("1.4.0"),
19+
new Version("1.5.0")
1920
)
2021

2122
override val systemSettingMenus: Seq[(Context) => Option[Link]] = Seq(

src/main/scala/fr/brouillard/gitbucket/h2/controller/H2BackupController.scala

+7-6
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ class H2BackupController extends ControllerBase with AdminAuthenticator {
2727
// private val defaultBackupFile:String = new File(GitBucketHome, "gitbucket-database-backup.zip").toString;
2828

2929
def exportDatabase(exportFile: File): Unit = {
30-
val destFile = if (exportFile.isAbsolute()) exportFile else new File(GitBucketHome, exportFile.toString)
30+
val destFile = if (exportFile.isAbsolute()) exportFile else new File(GitBucketHome+"/backup", exportFile.toString)
3131

3232
val session = Database.getSession(request)
3333
val conn = session.conn
3434

3535
logger.info("exporting database to {}", destFile)
3636

37-
conn.prepareStatement("BACKUP TO '" + destFile + "'").execute();
37+
conn.prepareStatement("BACKUP TO '" + destFile + "'").execute()
3838
}
3939

4040
get("/admin/h2backup") (adminOnly {
41-
html.export(flash.get("info"), flash.get("dest").orElse(Some(defaultBackupFileName())));
41+
html.export(flash.get("info"), flash.get("dest").orElse(Some(defaultBackupFileName())))
4242
})
4343

4444
get("/api/v3/plugins/database/backup") {
@@ -64,13 +64,14 @@ class H2BackupController extends ControllerBase with AdminAuthenticator {
6464

6565
post("/database/backup", backupForm) { form: BackupForm =>
6666
exportDatabase(new File(form.destFile))
67-
flash += "info" -> "H2 Database has been exported."
67+
val msg:String = "H2 Database has been exported to '"+form.destFile+"'."
68+
flash += "info" -> msg
6869
flash += "dest" -> form.destFile
6970
redirect("/admin/h2backup")
7071
}
7172

7273
private def defaultBackupFileName(): String = {
73-
val format = new java.text.SimpleDateFormat("yyyy-MM-dd-HHmm")
74-
"gitbucket-database-backup-" + format.format(new Date())+ ".zip";
74+
val format = new java.text.SimpleDateFormat("yyyy-MM-dd_HH-mm")
75+
"gitbucket-db-" + format.format(new Date())+ ".zip"
7576
}
7677
}

src/main/twirl/fr/brouillard/gitbucket/h2/export.scala.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
@information(info)
1111
<form action="@path/database/backup" method="POST">
1212
<div class="panel panel-default">
13-
<div class="panel-heading strong">Database backup</div>
13+
<div class="panel-heading strong">H2 Database Backup</div>
1414
<div class="panel-body">
1515
<fieldset>
16-
<label><span class="strong">Database backup file:</span></label>
16+
<label><span class="strong">H2 Database Backup File:</span></label>
1717
<p class="muted">
18-
Allows to export/backup the database content. The same action can be achieved via an HTTP GET call to @path/database/backup
18+
Allows to export/backup the H2 database content. The same action can be achieved via an HTTP GET call to @path/database/backup .
1919
</p>
20-
<input type="text" name="dest" value="@dest" style="width: 400px" />
20+
backup/<input type="text" name="dest" value="@dest" style="width: 400px" />
2121
</fieldset>
2222
</div>
2323
</div>

0 commit comments

Comments
 (0)