All Downloads are FREE. Search and download functionalities are using the official Maven repository.

au.net.causal.maven.plugins.boxdb.BackupMojo Maven / Gradle / Ivy

There is a newer version: 3.3
Show newest version
package au.net.causal.maven.plugins.boxdb;

import au.net.causal.maven.plugins.boxdb.db.BackupFileTypeHint;
import au.net.causal.maven.plugins.boxdb.db.BoxDatabaseException;
import au.net.causal.maven.plugins.boxdb.db.DockerService;
import io.fabric8.maven.docker.access.DockerAccessException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;

@Mojo(name="backup", requiresProject = false)
public class BackupMojo extends StartMojo
{
    @Parameter(property = "db.backupFile", defaultValue = "${project.build.directory}/dbbackup", required = true)
    private File backupFile;

    @Parameter(property = "db.backupType", defaultValue = "COMPACT", required = true)
    private BackupFileTypeHint backupType;

    @Override
    protected void executeInternal(ExceptionalSupplier dockerService)
    throws DockerAccessException, MojoExecutionException
    {
        //Start
        super.executeInternal(dockerService);

        try
        {
            getLog().info("Backing up database to " + backupFile.getAbsolutePath() + "...");
            database(dockerService).backup(backupFile.toPath(), backupType);
            getLog().info("Backup complete.");
        }
        catch (BoxDatabaseException | IOException | SQLException e)
        {
            throw new MojoExecutionException("Error backing up database: " + e, e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy