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
parent
3602b4e1ce
commit
2f53ee9cda
|
@ -126,6 +126,8 @@ def _parse_args():
|
||||||
help='Log file path')
|
help='Log file path')
|
||||||
parser.add_argument('--log-level', '-D', default='INFO', metavar='LEVEL',
|
parser.add_argument('--log-level', '-D', default='INFO', metavar='LEVEL',
|
||||||
help='Log 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,
|
parser.add_argument('--pretend', '-p', action='store_true', default=False,
|
||||||
help='Execute a dry run')
|
help='Execute a dry run')
|
||||||
parser.add_argument('--include', '-I', action='append',
|
parser.add_argument('--include', '-I', action='append',
|
||||||
|
@ -144,13 +146,18 @@ def main():
|
||||||
args = _parse_args()
|
args = _parse_args()
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read_file(args.config)
|
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 = Backup(config, args.destination, args.pretend)
|
||||||
backup.logsetup(args.log_file, args.log_level)
|
backup.logsetup(args.log_file, args.log_level)
|
||||||
if not backup.backup_all(args.include, args.exclude):
|
if not backup.backup_all(args.include, args.exclude):
|
||||||
sys.stderr.write('Errors occurred during backup\n')
|
sys.stderr.write('Errors occurred during backup\n')
|
||||||
if args.log_file and args.log_file != '-':
|
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)
|
raise SystemExit(1)
|
||||||
|
if not args.quiet:
|
||||||
|
print('Backup completed successfully')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue