@@ -8,31 +8,43 @@ import gitbucket.core.util.Directory._
88import fr .brouillard .gitbucket .h2 ._
99import org .scalatra .Ok
1010import org .slf4j .LoggerFactory
11+ import jp .sf .amateras .scalatra .forms ._
1112
1213class 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 }
0 commit comments