]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.server.core/src/main/java/org/argeo/server/backup/PostgreSqlBackup.java
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.server
.backup
;
18 import org
.apache
.commons
.vfs
.FileObject
;
20 /** Backups a PostgreSQL database using pg_dump. */
21 public class PostgreSqlBackup
extends OsCallBackup
{
23 * PostgreSQL password environment variable (see
24 * http://stackoverflow.com/questions
25 * /2893954/how-to-pass-in-password-to-pg-dump)
27 protected final static String PGPASSWORD
= "PGPASSWORD";
29 private String pgDumpLocation
= "/usr/bin/pg_dump";
31 private String dbUser
;
32 private String dbPassword
;
33 private String dbName
;
35 public PostgreSqlBackup() {
39 public PostgreSqlBackup(String dbUser
, String dbPassword
, String dbName
) {
41 this.dbPassword
= dbPassword
;
48 // disable compression since pg_dump is used with -Fc option
51 if (getName() == null)
52 setName(dbName
+ ".pgdump");
57 public void writeBackup(FileObject targetFo
) {
58 if (getCommand() == null) {
59 getEnvironment().put(PGPASSWORD
, dbPassword
);
60 setCommand(pgDumpLocation
+ " -Fc" + " -U ${dbUser} ${dbName}");
62 getVariables().put("dbUser", dbUser
);
63 getVariables().put("dbPassword", dbPassword
);
64 getVariables().put("dbName", dbName
);
66 super.writeBackup(targetFo
);
69 public void setDbUser(String dbUser
) {
73 public void setDbPassword(String dbPassword
) {
74 this.dbPassword
= dbPassword
;
77 public void setDbName(String dbName
) {
81 public void setPgDumpLocation(String mysqldumpLocation
) {
82 this.pgDumpLocation
= mysqldumpLocation
;