Skip to content

Commit 55ca3be

Browse files
committed
update version to 1.3.0, compatibility with gitbucket 4.3.0, fixes #12, #14
1 parent d70a6c7 commit 55ca3be

File tree

11 files changed

+65
-55
lines changed

11 files changed

+65
-55
lines changed

README.MD

+14-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ The plugin provides 2 ways to backup the H2 database:
1717
- via an administration page and a backup button
1818
- via an HTTP call to http://YOUR_GITBUCKET/database/backup
1919

20-
Default backup file points to `GITBUCKET_DATA/gitbucket-database-backup.zip` where _GITBUCKET_DATA_ is on a standard gitbucket installation `~/.gitbucket`
20+
Default backup file points to `GITBUCKET_DATA/gitbucket-database-backup-YYYY-MM-DD-hhmm.zip` where:
21+
22+
- _GITBUCKET_DATA_ is on a standard gitbucket installation `~/.gitbucket`
23+
- _YYYY-MM-DD-hhmm_ represents a date with hour
2124

2225
### UI usage
2326

@@ -29,18 +32,20 @@ Default backup file points to `GITBUCKET_DATA/gitbucket-database-backup.zip` whe
2932

3033
### HTTP call usage
3134

32-
Using your prefered tool (curl, wget, ...) it is possible fire a backup of the H2 database.
35+
Using your preferred tool (curl, wget, ...) it is possible fire a backup of the H2 database.
3336

3437
The URL to call looks like `http://YOUR_GITBUCKET/database/backup`.
3538

3639
You can pass an optional argument `dest` that references the destination file path where the backup will be done on the server. For example calling `http://YOUR_GITBUCKET/database/backup?dest=/var/backups/gitbucket.zip` will do an H2 backup of the gitbucket database into the file `/var/backups/gitbucket.zip`.
40+
Since `1.3.0`, the _dest_ parameter can denote a relative file path, in this case the file will be created relatively to `GITBUCKET_DATA`.
3741

38-
On success, you will receive a `HTTP 200` answer with a body containing the word `done`.
42+
On success, you will receive a `HTTP 200` answer with a body containing `done: FULL_PATH_OF_BACKUP_FILE`.
3943

4044
## Compatibility
4145

4246
Plugin version | GitBucket version
4347
:--------------|:-----------------
48+
1.3.x | >= 4.3.y
4449
1.2.x | 4.x.y
4550
1.1.x | 3.11.x
4651
1.0.x | 3.6.x, 3.7.x, 3.8.x,, 3.9.x, 3.10.x
@@ -58,6 +63,12 @@ sbt clean package
5863

5964
## Release Notes
6065

66+
### 1.3.0
67+
68+
- compatibility with gitbucket 4.3.0
69+
- fix version order in gitbucket Plugins panel
70+
- default backup file contains date with timestamp [#12](https://github.com/gitbucket-plugins/gitbucket-h2-backup-plugin/issues/12)
71+
6172
### 1.2.0
6273

6374
- binary compatibility with gitbucket 4.x

build.sbt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
val Organization = "fr.brouillard.gitbucket"
2+
val ProjectName = "gitbucket-h2-backup-plugin"
3+
val ProjectVersion = "1.3.0"
4+
5+
lazy val root = (project in file(".")).enablePlugins(SbtTwirl)
6+
7+
organization := Organization
8+
name := ProjectName
9+
version := ProjectVersion
10+
scalaVersion := "2.11.8"
11+
12+
resolvers ++= Seq(
13+
Classpaths.typesafeReleases,
14+
"central" at "http://repo.maven.apache.org/maven2/",
15+
"amateras" at "http://amateras.sourceforge.jp/mvn/"
16+
)
17+
18+
libraryDependencies ++= Seq(
19+
"io.github.gitbucket" %% "gitbucket" % "4.3.0" % "provided",
20+
"io.github.gitbucket" % "solidbase" % "1.0.0" % "provided",
21+
"com.typesafe.play" %% "twirl-compiler" % "1.0.4" % "provided",
22+
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided"
23+
)
24+
25+
scalacOptions := Seq("-deprecation", "-feature", "-language:postfixOps")
26+
javacOptions in compile ++= Seq("-target", "7", "-source", "7")

project/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version = 0.13.5
1+
sbt.version = 0.13.9

project/build.scala

-32
This file was deleted.

project/plugins.sbt

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
logLevel := Level.Warn
22

3-
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.0.2")
4-
5-
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")
3+
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.0.4")

sbt-launch-0.13.5.jar

-1.13 MB
Binary file not shown.

sbt-launch-0.13.9.jar

1.15 MB
Binary file not shown.

sbt.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
set SCRIPT_DIR=%~dp0
2-
java -Dsbt.log.noformat=true -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -jar "%SCRIPT_DIR%\sbt-launch-0.13.5.jar" %*
2+
java -Dsbt.log.noformat=true -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -jar "%SCRIPT_DIR%\sbt-launch-0.13.9.jar" %*

sbt.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/sh
2-
java -Dsbt.log.noformat=true -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -jar `dirname $0`/sbt-launch-0.13.5.jar "$@"
2+
java -Dsbt.log.noformat=true -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -jar `dirname $0`/sbt-launch-0.13.9.jar "$@"

src/main/scala/Plugin.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class Plugin extends gitbucket.core.plugin.Plugin {
1313

1414
override val versions: List[Version] = List(
1515
new Version("1.0.0"),
16-
new Version("1.2.0")
16+
new Version("1.2.0"),
17+
new Version("1.2.1")
1718
)
1819

1920
override val systemSettingMenus: Seq[(Context) => Option[Link]] = Seq(
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package fr.brouillard.gitbucket.h2.controller
22

33
import java.io.File
4+
import java.util.Date
5+
6+
import fr.brouillard.gitbucket.h2._
47

58
import gitbucket.core.controller.ControllerBase
6-
import gitbucket.core.servlet.Database
79
import gitbucket.core.util.AdminAuthenticator
810
import gitbucket.core.util.Directory._
9-
import fr.brouillard.gitbucket.h2._
11+
import gitbucket.core.servlet.Database
12+
1013
import org.scalatra.Ok
1114
import org.slf4j.LoggerFactory
15+
1216
import io.github.gitbucket.scalatra.forms._
1317

1418
class H2BackupController extends ControllerBase with AdminAuthenticator {
@@ -20,30 +24,27 @@ class H2BackupController extends ControllerBase with AdminAuthenticator {
2024
"dest" -> trim(label("Destination", text(required)))
2125
)(BackupForm.apply)
2226

23-
private val defaultBackupFile:String = new File(GitBucketHome, "gitbucket-database-backup.zip").toString;
27+
// private val defaultBackupFile:String = new File(GitBucketHome, "gitbucket-database-backup.zip").toString;
2428

2529
def exportDatabase(exportFile: File): Unit = {
30+
val destFile = if (exportFile.isAbsolute()) exportFile else new File(GitBucketHome, exportFile.toString)
31+
2632
val session = Database.getSession(request)
2733
val conn = session.conn
2834

29-
logger.info("exporting database to {}", exportFile)
30-
31-
conn.prepareStatement("BACKUP TO '" + exportFile + "'").execute();
32-
}
35+
logger.info("exporting database to {}", destFile)
3336

34-
def exportDatabase: Unit = {
35-
val exportFile = new File(GitBucketHome, "gitbucket-database-backup.zip")
36-
exportDatabase(exportFile);
37+
conn.prepareStatement("BACKUP TO '" + destFile + "'").execute();
3738
}
3839

3940
get("/admin/h2backup") (adminOnly {
40-
html.export(flash.get("info"), flash.get("dest").orElse(Some(defaultBackupFile)));
41+
html.export(flash.get("info"), flash.get("dest").orElse(Some(defaultBackupFileName())));
4142
})
4243

4344
get("/database/backup") {
44-
val filePath:String = params.getOrElse("dest", defaultBackupFile)
45+
val filePath:String = params.getOrElse("dest", defaultBackupFileName())
4546
exportDatabase(new File(filePath))
46-
Ok("done")
47+
Ok("done: " + filePath)
4748
}
4849

4950
post("/database/backup", backupForm) { form: BackupForm =>
@@ -52,4 +53,9 @@ class H2BackupController extends ControllerBase with AdminAuthenticator {
5253
flash += "dest" -> form.destFile
5354
redirect("/admin/h2backup")
5455
}
56+
57+
private def defaultBackupFileName(): String = {
58+
val format = new java.text.SimpleDateFormat("yyyy-MM-dd-HHmm")
59+
"gitbucket-database-backup-" + format.format(new Date())+ ".zip";
60+
}
5561
}

0 commit comments

Comments
 (0)