backup: check for disk space if target is local directory

This commit is contained in:
Marek Marczykowski-Górecki 2013-11-24 03:15:44 +01:00
parent 51f119326b
commit e7701d9c5d
2 changed files with 13 additions and 9 deletions

View File

@ -964,19 +964,10 @@ def backup_prepare(base_backup_dir, vms_list = None, exclude_list = [], print_ca
fmt="{{0:-^{0}}}-+".format(f["width"] + 1)
s += fmt.format('-')
print_callback(s)
# TODO: check at least if backing up to local drive
'''
stat = os.statvfs(base_backup_dir)
backup_fs_free_sz = stat.f_bsize * stat.f_bavail
print_callback("")
if (total_backup_sz > backup_fs_free_sz):
raise QubesException("Not enough space available on the backup filesystem!")
if (there_are_running_vms):
raise QubesException("Please shutdown all VMs before proceeding.")
print_callback("-> Available space: {0}".format(size_to_human(backup_fs_free_sz)))
'''
return files_to_backup
def backup_do(base_backup_dir, files_to_backup, progress_callback = None):

View File

@ -75,6 +75,19 @@ def main():
print >>sys.stderr, "ERROR: %s" % str(e)
exit(1)
total_backup_sz = reduce(lambda size, file: size+file["size"],
files_to_backup, 0)
if not options.appvm:
stat = os.statvfs(base_backup_dir)
backup_fs_free_sz = stat.f_bsize * stat.f_bavail
print
if (total_backup_sz > backup_fs_free_sz):
print >>sys.stderr, "ERROR: Not enough space available on the backup filesystem!"
exit(1)
print "-> Available space: {0}".format(size_to_human(backup_fs_free_sz))
prompt = raw_input ("Do you want to proceed? [y/N] ")
if not (prompt == "y" or prompt == "Y"):
exit (0)