Skip to content

Commit 04b4189

Browse files
committed
allow to optionally specify backup file. closes #2, closes #3
1 parent 27c4e52 commit 04b4189

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,43 @@ import gitbucket.core.util.Directory._
88
import fr.brouillard.gitbucket.h2._
99
import org.scalatra.Ok
1010
import org.slf4j.LoggerFactory
11+
import jp.sf.amateras.scalatra.forms._
1112

1213
class H2BackupController extends ControllerBase {
1314
private val logger = LoggerFactory.getLogger(classOf[H2BackupController])
1415

15-
def exportDatabase: Unit = {
16+
case class BackupForm(destFile: String)
17+
18+
private val backupForm = mapping(
19+
"dest" -> trim(label("Destination", text(required)))
20+
)(BackupForm.apply)
21+
22+
def exportDatabase(exportFile: File): Unit = {
1623
val session = Database.getSession(request)
1724
val conn = session.conn
18-
val exportFile = new File(GitBucketHome, "gitbucket-database-backup.zip")
1925

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

2228
conn.prepareStatement("BACKUP TO '" + exportFile + "'").execute();
2329
}
2430

31+
def exportDatabase: Unit = {
32+
val exportFile = new File(GitBucketHome, "gitbucket-database-backup.zip")
33+
exportDatabase(exportFile);
34+
}
35+
2536
get("/admin/h2backup") {
2637
html.export(flash.get("info"));
2738
}
2839

2940
get("/database/backup") {
30-
exportDatabase
41+
val filePath:String = params.getOrElse("dest", new File(GitBucketHome, "gitbucket-database-backup.zip").toString)
42+
exportDatabase(new File(filePath))
3143
Ok("done")
3244
}
3345

34-
post("/database/backup") {
35-
exportDatabase
46+
post("/database/backup", backupForm) { form: BackupForm =>
47+
exportDatabase(new File(form.destFile))
3648
flash += "info" -> "H2 Database has been exported."
3749
redirect("/admin/h2backup")
3850
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,19 @@
1212
<div class="box">
1313
<div class="box-header">Database export</div>
1414
<div class="box-content">
15-
<label><span class="strong">Database export file:</span>@GitBucketHome/gitbucket-database-backup.zip</label>
16-
<p class="muted">
17-
Allows to export the database content. The same action can be achieved via an HTTP GET call to @path/database/backup
18-
</p>
19-
2015
<fieldset>
21-
<input type="submit" class="btn btn-primary" value="Export database"/>
16+
<label><span class="strong">Database export file:</span></label>
17+
<p class="muted">
18+
Allows to export the database content. The same action can be achieved via an HTTP GET call to @path/database/backup
19+
</p>
20+
<input type="text" name="dest" value="@GitBucketHome/gitbucket-database-backup.zip" style="width: 400px" />
2221
</fieldset>
22+
2323
</div>
2424
</div>
25+
<div class="align-right" style="margin-top: 20px;">
26+
<input type="submit" class="btn btn-success" value="Export database"/>
27+
</div>
2528
</form>
2629
}
2730
}

0 commit comments

Comments
 (0)