au.net.causal.maven.plugins.boxdb.BackupMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of boxdb-maven-plugin Show documentation
Show all versions of boxdb-maven-plugin Show documentation
Maven plugin to start databases using Docker and VMs
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);
}
}
}