X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=cms%2Forg.argeo.cms.integration%2Fsrc%2Forg%2Fargeo%2Fmaintenance%2Fbackup%2Fvfs%2FPostgreSqlBackup.java;fp=cms%2Forg.argeo.cms.integration%2Fsrc%2Forg%2Fargeo%2Fmaintenance%2Fbackup%2Fvfs%2FPostgreSqlBackup.java;h=5a00c24e0841aaa5ce94d3e0cf0eea3aa97a9261;hb=d3bee9f6a2c9aea9bc9ab631e935794dcba39b03;hp=0000000000000000000000000000000000000000;hpb=ecc22e604e47533c79de9cecdcdeacbc752cbff1;p=gpl%2Fargeo-slc.git diff --git a/cms/org.argeo.cms.integration/src/org/argeo/maintenance/backup/vfs/PostgreSqlBackup.java b/cms/org.argeo.cms.integration/src/org/argeo/maintenance/backup/vfs/PostgreSqlBackup.java new file mode 100644 index 000000000..5a00c24e0 --- /dev/null +++ b/cms/org.argeo.cms.integration/src/org/argeo/maintenance/backup/vfs/PostgreSqlBackup.java @@ -0,0 +1,70 @@ +package org.argeo.maintenance.backup.vfs; + +import org.apache.commons.vfs2.FileObject; + +/** Backups a PostgreSQL database using pg_dump. */ +public class PostgreSqlBackup extends OsCallBackup { + /** + * PostgreSQL password environment variable (see + * http://stackoverflow.com/questions + * /2893954/how-to-pass-in-password-to-pg-dump) + */ + protected final static String PGPASSWORD = "PGPASSWORD"; + + private String pgDumpLocation = "/usr/bin/pg_dump"; + + private String dbUser; + private String dbPassword; + private String dbName; + + public PostgreSqlBackup() { + super(); + } + + public PostgreSqlBackup(String dbUser, String dbPassword, String dbName) { + this.dbUser = dbUser; + this.dbPassword = dbPassword; + this.dbName = dbName; + init(); + } + + @Override + public void init() { + // disable compression since pg_dump is used with -Fc option + setCompression(null); + + if (getName() == null) + setName(dbName + ".pgdump"); + super.init(); + } + + @Override + public void writeBackup(FileObject targetFo) { + if (getCommand() == null) { + getEnvironment().put(PGPASSWORD, dbPassword); + setCommand(pgDumpLocation + " -Fc" + " -U ${dbUser} ${dbName}"); + } + getVariables().put("dbUser", dbUser); + getVariables().put("dbPassword", dbPassword); + getVariables().put("dbName", dbName); + + super.writeBackup(targetFo); + } + + public void setDbUser(String dbUser) { + this.dbUser = dbUser; + } + + public void setDbPassword(String dbPassword) { + this.dbPassword = dbPassword; + } + + public void setDbName(String dbName) { + this.dbName = dbName; + } + + public void setPgDumpLocation(String mysqldumpLocation) { + this.pgDumpLocation = mysqldumpLocation; + } + +}