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.
master
Dustin C. Hatch 2014-10-12 18:25:53 -05:00
parent 3602b4e1ce
commit 2f53ee9cda
1 changed files with 8 additions and 1 deletions

View File

@ -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__':