]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.cms/src/org/argeo/slc/backup/vfs/PostgreSqlBackup.java
Adapt to new build system
[gpl/argeo-slc.git] / org.argeo.slc.cms / src / org / argeo / slc / backup / vfs / PostgreSqlBackup.java
1 package org.argeo.slc.backup.vfs;
2
3 import org.apache.commons.vfs2.FileObject;
4
5 /** Backups a PostgreSQL database using pg_dump. */
6 public class PostgreSqlBackup extends OsCallBackup {
7 /**
8 * PostgreSQL password environment variable (see
9 * http://stackoverflow.com/questions
10 * /2893954/how-to-pass-in-password-to-pg-dump)
11 */
12 protected final static String PGPASSWORD = "PGPASSWORD";
13
14 private String pgDumpLocation = "/usr/bin/pg_dump";
15
16 private String dbUser;
17 private String dbPassword;
18 private String dbName;
19
20 public PostgreSqlBackup() {
21 super();
22 }
23
24 public PostgreSqlBackup(String dbUser, String dbPassword, String dbName) {
25 this.dbUser = dbUser;
26 this.dbPassword = dbPassword;
27 this.dbName = dbName;
28 init();
29 }
30
31 @Override
32 public void init() {
33 // disable compression since pg_dump is used with -Fc option
34 setCompression(null);
35
36 if (getName() == null)
37 setName(dbName + ".pgdump");
38 super.init();
39 }
40
41 @Override
42 public void writeBackup(FileObject targetFo) {
43 if (getCommand() == null) {
44 getEnvironment().put(PGPASSWORD, dbPassword);
45 setCommand(pgDumpLocation + " -Fc" + " -U ${dbUser} ${dbName}");
46 }
47 getVariables().put("dbUser", dbUser);
48 getVariables().put("dbPassword", dbPassword);
49 getVariables().put("dbName", dbName);
50
51 super.writeBackup(targetFo);
52 }
53
54 public void setDbUser(String dbUser) {
55 this.dbUser = dbUser;
56 }
57
58 public void setDbPassword(String dbPassword) {
59 this.dbPassword = dbPassword;
60 }
61
62 public void setDbName(String dbName) {
63 this.dbName = dbName;
64 }
65
66 public void setPgDumpLocation(String mysqldumpLocation) {
67 this.pgDumpLocation = mysqldumpLocation;
68 }
69
70 }