def handle_label(self, label, **options): db_conf = get_db_conf(options) backup_handler = getattr(self, '_backup_%s_db' % db_conf['engine']) try: tmp_outfile = tempfile.NamedTemporaryFile(mode='w') ret, outfile = backup_handler(db_conf, "%s-%s" % (label, time.strftime('%Y-%m-%d-%H%M')), tmp_outfile) if ret: raise IOError() _check_writable(outfile) ret = os.system('gzip -c %s -9 > %s' % (tmp_outfile.name, outfile)) if ret: raise IOError() except IOError: # Cleanup empty output file if something went wrong os.system('rm %s' % outfile) raise CommandError("Database '%s' backup to '%s' failed" % (db_conf['db_name'], outfile)) finally: tmp_outfile.close() print ("Database '%s' successfully backed up to: %s" % (db_conf['db_name'], outfile))
def handle_label(self, label, **options): db_conf = get_db_conf(options) backup_handler = getattr(self, '_backup_%s_db' % db_conf['engine']) try: tmp_outfile = tempfile.NamedTemporaryFile(mode='w') ret, outfile = backup_handler( db_conf, "%s-%s" % (label, time.strftime('%Y-%m-%d-%H%M')), tmp_outfile) if ret: raise IOError() _check_writable(outfile) ret = os.system('gzip -c %s -9 > %s' % (tmp_outfile.name, outfile)) if ret: raise IOError() except IOError: # Cleanup empty output file if something went wrong os.system('rm %s' % outfile) raise CommandError("Database '%s' backup to '%s' failed" % (db_conf['db_name'], outfile)) finally: tmp_outfile.close() print("Database '%s' successfully backed up to: %s" % (db_conf['db_name'], outfile))
def handle_label(self, label, **options): db_conf = get_db_conf(options) backup_handler = getattr(self, '_backup_%s_db' % db_conf['engine']) ret, outfile = backup_handler(db_conf, "%s-%s" % (label, time.strftime('%Y-%m-%d-%H%M'))) if not ret: print ("Database '%s' successfully backed up to: %s" % (db_conf['db_name'], outfile)) else: raise CommandError("Database '%s' backup to '%s' failed" % (db_conf['db_name'], outfile))
def handle_label(self, label, **options): if not os.access(label, os.R_OK): raise CommandError("File '%s' is not readable." % label) db_conf = get_db_conf(options) if _confirm(options["interactive"], db_conf["db_name"]) == "yes": load_handler = getattr(self, "_load_%s_db" % db_conf["engine"]) ret = load_handler(db_conf, label) if not ret: print ("Data from '%s' was successfully loaded to '%s'" % (label, db_conf["db_name"])) else: raise CommandError("Loading data from '%s' to '%s' failed" % (label, db_conf["db_name"])) else: print "Cancelled."