Revise help and stderr messages

This commit is contained in:
Andrew David Wong 2016-07-15 16:20:11 -07:00
parent 4072914b40
commit 1d625b3570
No known key found for this signature in database
GPG Key ID: DB4DD3BC39503030

View File

@ -41,39 +41,41 @@ def main():
parser.add_option ("-x", "--exclude", action="append", parser.add_option ("-x", "--exclude", action="append",
dest="exclude_list", default=[], dest="exclude_list", default=[],
help="Exclude the specified VM from backup (may be " help="Exclude the specified VM from the backup (may be "
"repeated)") "repeated)")
parser.add_option ("--force-root", action="store_true", dest="force_root", default=False, parser.add_option ("--force-root", action="store_true", dest="force_root", default=False,
help="Force to run, even with root privileges") help="Force to run with root privileges")
parser.add_option ("-d", "--dest-vm", action="store", dest="appvm", parser.add_option ("-d", "--dest-vm", action="store", dest="appvm",
help="The AppVM to send backups to (implies -e)") help="Specify the destination VM to which the backup "
"will be sent (implies -e)")
parser.add_option ("-e", "--encrypt", action="store_true", dest="encrypt", default=False, parser.add_option ("-e", "--encrypt", action="store_true", dest="encrypt", default=False,
help="Encrypts the backup") help="Encrypt the backup")
parser.add_option ("--no-encrypt", action="store_true", parser.add_option ("--no-encrypt", action="store_true",
dest="no_encrypt", default=False, dest="no_encrypt", default=False,
help="Skip encryption even if sending the backup to VM") help="Skip encryption even if sending the backup to a "
"VM")
parser.add_option ("-p", "--passphrase-file", action="store", parser.add_option ("-p", "--passphrase-file", action="store",
dest="pass_file", default=None, dest="pass_file", default=None,
help="File containing the pass phrase to use, or '-' " help="Read passphrase from a file, or use '-' to read "
"to read it from stdin") "from stdin")
parser.add_option ("-E", "--enc-algo", action="store", parser.add_option ("-E", "--enc-algo", action="store",
dest="crypto_algorithm", default=None, dest="crypto_algorithm", default=None,
help="Specify non-default encryption algorithm. For " help="Specify a non-default encryption algorithm. For a "
"list of supported algos execute 'openssl " "list of supported algorithms, execute 'openssl "
"list-cipher-algorithms' (implies -e)") "list-cipher-algorithms' (implies -e)")
parser.add_option ("-H", "--hmac-algo", action="store", parser.add_option ("-H", "--hmac-algo", action="store",
dest="hmac_algorithm", default=None, dest="hmac_algorithm", default=None,
help="Specify non-default hmac algorithm. For list of " help="Specify a non-default HMAC algorithm. For a list "
"supported algos execute 'openssl " "of supported algorithms, execute 'openssl "
"list-message-digest-algorithms'") "list-message-digest-algorithms'")
parser.add_option ("-z", "--compress", action="store_true", dest="compress", default=False, parser.add_option ("-z", "--compress", action="store_true", dest="compress", default=False,
help="Compress the backup") help="Compress the backup")
parser.add_option ("-Z", "--compress-filter", action="store", parser.add_option ("-Z", "--compress-filter", action="store",
dest="compress_filter", default=False, dest="compress_filter", default=False,
help="Compress the backup using specified filter " help="Specify a non-default compression filter program "
"program (default: gzip)") "(default: gzip)")
parser.add_option("--tmpdir", action="store", dest="tmpdir", default=None, parser.add_option("--tmpdir", action="store", dest="tmpdir", default=None,
help="Custom temporary directory (if you have at least " help="Specify a temporary directory (if you have at least "
"1GB free RAM in dom0, use of /tmp is advised) (" "1GB free RAM in dom0, use of /tmp is advised) ("
"default: /var/tmp)") "default: /var/tmp)")
parser.add_option ("--debug", action="store_true", dest="debug", parser.add_option ("--debug", action="store_true", dest="debug",
@ -82,17 +84,21 @@ def main():
(options, args) = parser.parse_args () (options, args) = parser.parse_args ()
if (len (args) < 1): if (len (args) < 1):
print >> sys.stderr, "You must specify the target backup directory (e.g. /mnt/backup)" print >> sys.stderr, "You must specify the target backup directory "\
print >> sys.stderr, "qvm-backup will create a subdirectory there for each individual backup." " (e.g. /mnt/backup)."
print >> sys.stderr, "qvm-backup will create a subdirectory there for "\
" each individual backup."
exit (0) exit (0)
base_backup_dir = args[0] base_backup_dir = args[0]
if hasattr(os, "geteuid") and os.geteuid() == 0: if hasattr(os, "geteuid") and os.geteuid() == 0:
if not options.force_root: if not options.force_root:
print >> sys.stderr, "*** Running this tool as root is strongly discouraged, this will lead you in permissions problems." print >> sys.stderr, "*** Running this tool as root is strongly "\
print >> sys.stderr, "Retry as unprivileged user." "discouraged. This will lead to permissions "\
print >> sys.stderr, "... or use --force-root to continue anyway." "problems."
print >> sys.stderr, "Retry as an unprivileged user, or use "\
"--force-root to continue anyway."
exit(1) exit(1)
# Only for locking # Only for locking
@ -136,14 +142,15 @@ def main():
backup_fs_free_sz = stat.f_bsize * stat.f_bavail backup_fs_free_sz = stat.f_bsize * stat.f_bavail
print print
if (total_backup_sz > backup_fs_free_sz): if (total_backup_sz > backup_fs_free_sz):
print >>sys.stderr, "ERROR: Not enough space available on the backup filesystem!" print >>sys.stderr, "ERROR: Not enough space available on the "\
"backup filesystem!"
exit(1) exit(1)
print "-> Available space: {0}".format(size_to_human(backup_fs_free_sz)) print "-> Available space: {0}".format(size_to_human(backup_fs_free_sz))
else: else:
appvm = qvm_collection.get_vm_by_name(options.appvm) appvm = qvm_collection.get_vm_by_name(options.appvm)
if appvm is None: if appvm is None:
print >>sys.stderr, "ERROR: VM {0} does not exist".format(options.appvm) print >>sys.stderr, "ERROR: VM {0} does not exist!".format(options.appvm)
exit(1) exit(1)
stat = os.statvfs('/var/tmp') stat = os.statvfs('/var/tmp')
@ -151,19 +158,19 @@ def main():
print print
if (backup_fs_free_sz < 1000000000): if (backup_fs_free_sz < 1000000000):
print >>sys.stderr, "ERROR: Not enough space available " \ print >>sys.stderr, "ERROR: Not enough space available " \
"on the local filesystem (needs 1GB for temporary files)!" "on the local filesystem (1GB required for temporary files)!"
exit(1) exit(1)
if not appvm.is_running(): if not appvm.is_running():
appvm.start(verbose=True) appvm.start(verbose=True)
if options.appvm: if options.appvm:
print >>sys.stderr, ("WARNING: VM {} excluded because it's used to " print >>sys.stderr, ("NOTE: VM {} will be excluded because it is "
"store the backup.").format(options.appvm) "the backup destination.").format(options.appvm)
options.exclude_list.append(options.appvm) options.exclude_list.append(options.appvm)
if not options.encrypt: if not options.encrypt:
print >>sys.stderr, "WARNING: encryption will not be used" print >>sys.stderr, "WARNING: The backup will NOT be encrypted!"
if options.pass_file is not None: if options.pass_file is not None:
f = open(options.pass_file) if options.pass_file != "-" else sys.stdin f = open(options.pass_file) if options.pass_file != "-" else sys.stdin
@ -175,12 +182,12 @@ def main():
if raw_input("Do you want to proceed? [y/N] ").upper() != "Y": if raw_input("Do you want to proceed? [y/N] ").upper() != "Y":
exit(0) exit(0)
s = ("Please enter the pass phrase that will be used to {}verify " s = ("Please enter the passphrase that will be used to {}verify "
"the backup: ").format('encrypt and ' if options.encrypt else '') "the backup: ").format('encrypt and ' if options.encrypt else '')
passphrase = getpass.getpass(s) passphrase = getpass.getpass(s)
if getpass.getpass("Enter again for verification: ") != passphrase: if getpass.getpass("Enter again for verification: ") != passphrase:
print >>sys.stderr, "ERROR: Password mismatch" print >>sys.stderr, "ERROR: Passphrase mismatch!"
exit(1) exit(1)
encoding = sys.stdin.encoding or getpreferredencoding() encoding = sys.stdin.encoding or getpreferredencoding()