From 2f53ee9cda8d41666c1b3806f1fd70d949b75695 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sun, 12 Oct 2014 18:25:53 -0500 Subject: [PATCH] backup: Print informational messages by default To ensure that output is generated, even when no errors occur, and thus cron sends an email message, we'll print some informational messages before and after running the backup. These can be switched off with the `-q`/`--quiet` argument. --- backup.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backup.py b/backup.py index 0a49a53..2120e5a 100755 --- a/backup.py +++ b/backup.py @@ -126,6 +126,8 @@ def _parse_args(): help='Log file path') parser.add_argument('--log-level', '-D', default='INFO', metavar='LEVEL', help='Log level') + parser.add_argument('--quiet', '-q', action='store_true', default=False, + help='Do not print informational messages') parser.add_argument('--pretend', '-p', action='store_true', default=False, help='Execute a dry run') parser.add_argument('--include', '-I', action='append', @@ -144,13 +146,18 @@ def main(): args = _parse_args() config = configparser.ConfigParser() config.read_file(args.config) + if not args.quiet: + print('Backing up to {} using configuration from {}'.format( + args.destination, args.config.name)) backup = Backup(config, args.destination, args.pretend) backup.logsetup(args.log_file, args.log_level) if not backup.backup_all(args.include, args.exclude): sys.stderr.write('Errors occurred during backup\n') if args.log_file and args.log_file != '-': - sys.stderr.write('See {} for details'.format(args.log_file)) + sys.stderr.write('See {} for details\n'.format(args.log_file)) raise SystemExit(1) + if not args.quiet: + print('Backup completed successfully') if __name__ == '__main__':