Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have returned a python script to take postgresql database dump of particular tables, how can I get the dump of that particular tables one day or incremental data to a .sql file.

username = 'postgres'
port = 5432
date = time.strftime('%Y-%m-%d')

base = 'databasename'
if base == 'databasename':

    filename = "%s/%s-%s.sql" % (fulldir, base, date)

    os.popen("nice -n 19 pg_dump -C -t table1 -t table2 -t table3 -t table4 -F p -U%s -p%s %s > %s" % (username, port, base, filename))
    print(base + "backup taken")
share|improve this question

You can make this python as an executable file and then open your linux terminal and edit the crontab using corntab -e command and put the command there

30 23 * * * your_executable_file_name

this will take the back up every day at 11:30 pm of your server time. Hope this will help you.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.