marklogic / ml-gradle

Gradle plugin for automating everything involving MarkLogic

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: back up db and restore db tasks

lingtao-sa opened this issue · comments

I want to trigger ML DB backup and restore from ML Gradle tasks.
Hence I could use it to automate my ML Admin work to sync the db between different environments.

I guess it fits into the ml-gradle project vision to Automate everything involving MarkLogic. ; )

There's a solution for this - you can write your own task, where you can specify the exact parameters you want.

For example, you could do something like this:

task backupMyDatabase(type: com.marklogic.gradle.task.MarkLogicTask) {
    doLast {
        // Add whatever JSON you want per https://docs.marklogic.com/REST/POST/manage/v2/databases/[id-or-name]#BackupDB 
        getManageClient().postJson("/manage/v2/databases/myDatabase, '{"operation":"backup"}')
    }
}

An ml-gradle task would need to support parameters for all of the possible inputs so you could do something like this:

./gradlew mlBackupDatabase -Pdatabase=myDatabase -PbackupDir=/tmp -Pincremental=true etc...

With the above, ml-gradle is adding a layer of abstraction - a set of Gradle params - that must now be documented on top of the well-documented JSON payload for backing up a database. I don't think there's any real value there. That applies for a restore operation as well.

I recommend first trying custom tasks that specify the precise JSON you want for backing up and restoring a database. If you find something to be inefficient with that approach, reply back here with the problem you're running into and how a "mlBackupDatabase" task with a bunch of params would help that.