Skip to content

Commit

Permalink
update version to 1.3.0, compatibility with gitbucket 4.3.0, fixes #12,
Browse files Browse the repository at this point in the history
  • Loading branch information
McFoggy committed Aug 6, 2016
1 parent d70a6c7 commit 55ca3be
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 55 deletions.
17 changes: 14 additions & 3 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ 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

Default backup file points to `GITBUCKET_DATA/gitbucket-database-backup.zip` where _GITBUCKET_DATA_ is on a standard gitbucket installation `~/.gitbucket`
Default backup file points to `GITBUCKET_DATA/gitbucket-database-backup-YYYY-MM-DD-hhmm.zip` where:

- _GITBUCKET_DATA_ is on a standard gitbucket installation `~/.gitbucket`
- _YYYY-MM-DD-hhmm_ represents a date with hour

### UI usage

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

### HTTP call usage

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

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

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`.
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`.

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

## Compatibility

Plugin version | GitBucket version
:--------------|:-----------------
1.3.x | >= 4.3.y
1.2.x | 4.x.y
1.1.x | 3.11.x
1.0.x | 3.6.x, 3.7.x, 3.8.x,, 3.9.x, 3.10.x
Expand All @@ -58,6 +63,12 @@ sbt clean package

## Release Notes

### 1.3.0

- compatibility with gitbucket 4.3.0
- fix version order in gitbucket Plugins panel
- default backup file contains date with timestamp [#12](https://github.com/gitbucket-plugins/gitbucket-h2-backup-plugin/issues/12)

### 1.2.0

- binary compatibility with gitbucket 4.x
Expand Down
26 changes: 26 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
val Organization = "fr.brouillard.gitbucket"
val ProjectName = "gitbucket-h2-backup-plugin"
val ProjectVersion = "1.3.0"

lazy val root = (project in file(".")).enablePlugins(SbtTwirl)

organization := Organization
name := ProjectName
version := ProjectVersion
scalaVersion := "2.11.8"

resolvers ++= Seq(
Classpaths.typesafeReleases,
"central" at "http://repo.maven.apache.org/maven2/",
"amateras" at "http://amateras.sourceforge.jp/mvn/"
)

libraryDependencies ++= Seq(
"io.github.gitbucket" %% "gitbucket" % "4.3.0" % "provided",
"io.github.gitbucket" % "solidbase" % "1.0.0" % "provided",
"com.typesafe.play" %% "twirl-compiler" % "1.0.4" % "provided",
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided"
)

scalacOptions := Seq("-deprecation", "-feature", "-language:postfixOps")
javacOptions in compile ++= Seq("-target", "7", "-source", "7")
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 0.13.5
sbt.version = 0.13.9
32 changes: 0 additions & 32 deletions project/build.scala

This file was deleted.

4 changes: 1 addition & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
logLevel := Level.Warn

addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.0.2")

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.0.4")
Binary file removed sbt-launch-0.13.5.jar
Binary file not shown.
Binary file added sbt-launch-0.13.9.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion sbt.bat
Original file line number Diff line number Diff line change
@@ -1,2 +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" %*
java -Dsbt.log.noformat=true -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -jar "%SCRIPT_DIR%\sbt-launch-0.13.9.jar" %*
2 changes: 1 addition & 1 deletion sbt.sh
Original file line number Diff line number Diff line change
@@ -1,2 +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 "$@"
java -Dsbt.log.noformat=true -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -jar `dirname $0`/sbt-launch-0.13.9.jar "$@"
3 changes: 2 additions & 1 deletion src/main/scala/Plugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Plugin extends gitbucket.core.plugin.Plugin {

override val versions: List[Version] = List(
new Version("1.0.0"),
new Version("1.2.0")
new Version("1.2.0"),
new Version("1.2.1")
)

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

import java.io.File
import java.util.Date

import fr.brouillard.gitbucket.h2._

import gitbucket.core.controller.ControllerBase
import gitbucket.core.servlet.Database
import gitbucket.core.util.AdminAuthenticator
import gitbucket.core.util.Directory._
import fr.brouillard.gitbucket.h2._
import gitbucket.core.servlet.Database

import org.scalatra.Ok
import org.slf4j.LoggerFactory

import io.github.gitbucket.scalatra.forms._

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

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

def exportDatabase(exportFile: File): Unit = {
val destFile = if (exportFile.isAbsolute()) exportFile else new File(GitBucketHome, exportFile.toString)

val session = Database.getSession(request)
val conn = session.conn

logger.info("exporting database to {}", exportFile)

conn.prepareStatement("BACKUP TO '" + exportFile + "'").execute();
}
logger.info("exporting database to {}", destFile)

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

get("/admin/h2backup") (adminOnly {
html.export(flash.get("info"), flash.get("dest").orElse(Some(defaultBackupFile)));
html.export(flash.get("info"), flash.get("dest").orElse(Some(defaultBackupFileName())));
})

get("/database/backup") {
val filePath:String = params.getOrElse("dest", defaultBackupFile)
val filePath:String = params.getOrElse("dest", defaultBackupFileName())
exportDatabase(new File(filePath))
Ok("done")
Ok("done: " + filePath)
}

post("/database/backup", backupForm) { form: BackupForm =>
Expand All @@ -52,4 +53,9 @@ class H2BackupController extends ControllerBase with AdminAuthenticator {
flash += "dest" -> form.destFile
redirect("/admin/h2backup")
}

private def defaultBackupFileName(): String = {
val format = new java.text.SimpleDateFormat("yyyy-MM-dd-HHmm")
"gitbucket-database-backup-" + format.format(new Date())+ ".zip";
}
}

0 comments on commit 55ca3be

Please sign in to comment.