I'm trying to export Postgresql database but it returns backup() takes no arguments (1 given). I tried various methods, but unable to export database.
from pathlib import Path, PureWindowsPath
from subprocess import PIPE,Popen
def backup():
version = 11
# postgresDir = "D:/Program Files (x86)/PostgreSQL/9.1/bin"
postgresDir = str("D:/Program Files (x86)/PostgreSQL/9.1/bin/").split('\\')[-1:][0]
directory = postgresDir
filename = 'myBackUp2' # output filename here
saveDir = Path("D:/{}.tar".format(filename)) # output directory here
file = PureWindowsPath(saveDir)
host = 'localhost'
user = 'postgres'
port = '5432'
dbname = 'BPS_Server' # database name here
proc = Popen(['pg_dump', '-h', host, '-U', user, '-W', '-p', port,
'-F', 't', '-f', str(file), '-d', dbname],
cwd=directory, shell=True, stdin=PIPE)
proc.wait()
backup()