Skip to content

Commit 625b196

Browse files
committed
Allow psycopg2 import failure if not actually running backup
1 parent 373b86b commit 625b196

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

defaults/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ postgresql_backup_command: >-
3636
--rsync-backup-opts {{ postgresql_backup_rsync_backup_opts | regex_replace('^-', '\-') | quote }}
3737
--keep {{ postgresql_backup_keep | quote }}
3838
{{ '--pg-bin-dir ' ~ __postgresql_pgdg_bin_dir if ansible_os_family == 'RedHat' else '' }}
39-
--backup --clean-archive {{ postgresql_backup_dir | quote }}
39+
--backup {{ (':' in postgresql_backup_dir) | ternary('', '--clean-archive') }} {{ postgresql_backup_dir | quote }}
4040
4141
postgresql_backup_python_executable: "python"
4242

files/backup.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
except ImportError:
3131
from pipes import quote as shlex_quote
3232

33-
import psycopg2
33+
try:
34+
import psycopg2
35+
except ImportError:
36+
psycopg2 = None
3437

3538

3639
RSYNC_EXCLUDES = (
@@ -147,6 +150,8 @@ def parse_args(argv):
147150
parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Verbose output')
148151
parser.add_argument('backup_path', help='Backup to location (rsync-compatible string)')
149152
args = parser.parse_args(argv)
153+
if args.backup and psycopg2 is None:
154+
parser.error('--backup specified but psycopg2 could not be imported')
150155
if args.clean_archive and ':' in args.backup_path:
151156
parser.error('--clean-archive cannot be used with remote backup directories')
152157
return args

0 commit comments

Comments
 (0)