Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1100149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:50:18+00:00 2026-05-17T00:50:18+00:00

In our application, we’ve implemented an automatic DB migration triggered from within our code.

  • 0

In our application, we’ve implemented an automatic DB migration triggered from within our code. Now we want to backup the existing DB before doing any migration.

Can anyone explain how to do a full backup of a Postgresql-DB via JDBC from within Java code?

Update: it doesn’t work via JDBC.

Here some working code to the response of Frank Heikens:

    final List<String> baseCmds = new ArrayList<String>();
    baseCmds.add("/usr/bin/pg_dump");
    baseCmds.add("-h");
    baseCmds.add("hostname");
    baseCmds.add("-p");
    baseCmds.add("5432");
    baseCmds.add("-U");
    baseCmds.add("username");
    baseCmds.add("-b");
    baseCmds.add("-v");
    baseCmds.add("-f");
    baseCmds.add("/path/to/backup.sql");
    baseCmds.add("dbName");
    final ProcessBuilder pb = new ProcessBuilder(baseCmds);

    // Set the password
    final Map<String, String> env = pb.environment();
    env.put("PGPASSWORD", "password");

    try {
        final Process process = pb.start();

        final BufferedReader r = new BufferedReader(
                  new InputStreamReader(process.getErrorStream()));
        String line = r.readLine();
        while (line != null) {
            System.err.println(line);
            line = r.readLine();
        }
        r.close();

        final int dcertExitCode = process.waitFor();

     } catch (IOException e) {
        e.printStackTrace();
     } catch (InterruptedException ie) {
        ie.printStackTrace();
     }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:50:18+00:00Added an answer on May 17, 2026 at 12:50 am

    Why don’t you use pg_dump?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our application takes text from a web form and sends it via email to
Our application downloads data from the internet using RSS but is having connection problems
Our application has a lot of .NET assemblies, which up until now, has not
Our application uses H2Sharp to access a H2 database from C# (Framework v4). Recently
Our application is getting a System Call Failed RPC error from DCOM ( 0x80010100
Our application is mining names from people using Twitter to login. Twitter is providing
Our application has a need to share an existing database table with another locally
Our application (C# .Net 3.5) works fine on WinXP machines (embedded or not). Now
Our application requires a user to select a photograph from their camera. The cameras
Our application has very large data and we want to perform our business logic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.