From: | "Vadim Pestovnikov" <vpestovnikov(at)yak(dot)ca> |
---|---|
To: | <pgsql-admin(at)postgresql(dot)org> |
Subject: | Python os.system module handle errors |
Date: | 2006-05-04 20:50:53 |
Message-ID: | 1B6B036445BFC94490C87AF12F102AD3144DC4@tofn-svr-exc-01.yak.ca |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
Hi all,
When I create a database dump in python script and if there are some errors (user_name is not correct, db_name doesn't exist or something else) I need to send e-mail notification to admin. How can I handle these errors?
Example:
----------------------------------------------------------------------------#!/usr/bin/python
import os
os.system("pg_dump -U user_name -i -F c -v db_name -f file_name.backup")
print "%s backup complete" % ("Database XXX")
----------------------------------------------------------------------------
I tried to use, but it doesn't work.
----------------------------------------------------------------------------
#!/usr/bin/python
import os
try:
os.system("pg_dump -U user_name -i -F c -v db_name -f file_name.backup")
print "%s backup complete" % ("Database XXX")
except os.error:
# ...
# here sending e-mail if there is an error of backing up
# ...
print "Backup error %s" % error
--
Vadim
From | Date | Subject | |
---|---|---|---|
Next Message | Sriram Dandapani | 2006-05-04 21:20:39 | reset all sequences |
Previous Message | Tom Lane | 2006-05-04 20:48:11 | Re: How to find current running process |