Skip to content

Escape schema name #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@

A Java tool to backup and restore PostgreSQL databases using JDBC.

QuickStart:

1. `git clone https://github.com/tig100/JdbcPgBackup.git && cd JdbcPgBackup`
1. Download jdbc lib from https://jdbc.postgresql.org/, and copy it into a `lib` folder
1. Compile

javac -cp ./jdbcpgbackup/:./lib/postgresql-9.3-1103.jdbc3.jar -d classes jdbcpgbackup/*.java
1. Run:

java -cp ./lib/postgresql-9.1-902.jdbc4.jar:./classes jdbcpgbackup.JdbcPgBackup \
-m dump -h dbhost -t -d dbname -U dbuser -P dbpassword \
-f output.dump

Usage:
java jdbcpgbackup.JdbcPgBackup -m dump|restore [-h hostname] [-p port] [-t (timing)]
[-d database] [-U user] [-P password] [-f filename] [-o (schema only)]
[-s schema[,schema...]] [-n schema[,schema...]] [-b batchsize]

```
java jdbcpgbackup.JdbcPgBackup -m dump|restore
[-h hostname] [-p port] [-t (timing)]
[-d database] [-U user] [-P password] [-f filename] [-o (schema only)]
[-s schema[,schema...]] [-n schema[,schema...]] [-b batchsize]
```

Options:
-m mode, dump or restore, required;
Expand Down
2 changes: 1 addition & 1 deletion jdbcpgbackup/Constraint.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public final Iterable<Constraint> getDbBackupObjects(Connection con, Schema sche
private Constraint(String name, Schema schema, String tableName, String tableOwner, String definition, char type) {
super(name, schema, tableOwner);
this.tableName = tableName;
this.definition = definition.replace(" REFERENCES " + schema.getName() + ".", " REFERENCES "); // remove schema name
this.definition = definition.replace(" REFERENCES \"" + schema.getName() + "\".", " REFERENCES "); // remove schema name
this.type = type;
}

Expand Down
2 changes: 1 addition & 1 deletion jdbcpgbackup/DbBackupObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final String getName() {
}

String getFullname() {
return schema.getName() + "." + name;
return "\"" + schema.getName() + "\"." + name;
}

final String getOwner() {
Expand Down
2 changes: 1 addition & 1 deletion jdbcpgbackup/Sequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static Sequence getSequence(Connection con, Schema schema, String sequen
Sequence sequence = null;
try {
stmt = con.prepareStatement(
"SELECT * FROM " + schema.getName() + "." + sequenceName);
"SELECT * FROM \"" + schema.getName() + "\"." + sequenceName);
ResultSet rs = stmt.executeQuery();
if (rs.next())
sequence = new Sequence(sequenceName, rs, schema, owner);
Expand Down