I had a program which makes PostgreSQL backups, and gives the user the chance to zip these backups:
if bkp_type == 'gz':
command = 'pg_dumpall -U {} -h {} -p {} | gzip > {}'.format(user, server, port, file)
elif bkp_type == 'bz2':
command = 'pg_dumpall -U {} -h {} -p {} | bzip2 > {}'.format(user, server, port, file)
elif bkp_type == 'zip':
command = 'pg_dumpall -U {} -h {} -p {} | zip > {}'.format(user, server, port, file)
else:
command = 'pg_dumpall -U {} -h {} -p {} > {}'.format(user, server, port, file)
result = subprocess.call(command, shell=True)
Now, I am using pg_restore to restore them, but I am not able to do it if the file is compressed. Is there any way to do it directly with pg_restore (like in pg_dump or pg_dumpall) or do I have to check the kind of compressing used and unzip them with Python?