def backup(filename, destination="s3", **kwargs): conf = kwargs.get("conf", None) storage_backend = storage_backends[destination](conf) log.info("Backing up " + filename) arcname = filename.split("/")[-1] stored_filename = arcname + datetime.now().strftime("%Y%m%d%H%M%S") + ".tgz" password = kwargs.get("password") if not password: password = getpass("Password (blank to disable encryption): ") if password: password2 = getpass("Password confirmation: ") if password != password2: log.error("Password confirmation doesn't match") return log.info("Compressing...") out = tempfile.TemporaryFile() with tarfile.open(fileobj=out, mode="w:gz") as tar: tar.add(filename, arcname=arcname) if password: log.info("Encrypting...") encrypted_out = tempfile.TemporaryFile() encrypt(out, encrypted_out, password) stored_filename += ".enc" out = encrypted_out log.info("Uploading...") out.seek(0) storage_backend.upload(stored_filename, out)
def backup(filename, **kwargs): log = kwargs.get("logger", app_logger) conf = kwargs.get("conf", None) bucket= get_bucket(conf) if not bucket: return log.info("Backing up " + filename) arcname = filename.split("/")[-1] out = StringIO() with tarfile.open(fileobj=out, mode="w:gz") as tar: tar.add(filename, arcname=arcname) password = kwargs.get("password") if not password: password = getpass() encrypted_out = StringIO() encrypt(out, encrypted_out, password) encrypted_out.seek(0) k = Key(bucket) k.key = arcname + datetime.now().strftime("%Y%m%d") + ".tgz.enc" k.set_contents_from_file(encrypted_out) k.set_acl("private")
def backup(filename, **kwargs): log = kwargs.get("logger", app_logger) conf = kwargs.get("conf", None) bucket = get_bucket(conf) if not bucket: return log.info("Backing up " + filename) arcname = filename.split("/")[-1] out = StringIO() with tarfile.open(fileobj=out, mode="w:gz") as tar: tar.add(filename, arcname=arcname) password = kwargs.get("password") if not password: password = getpass() encrypted_out = StringIO() encrypt(out, encrypted_out, password) encrypted_out.seek(0) k = Key(bucket) k.key = arcname + datetime.now().strftime("%Y%m%d") + ".tgz.enc" k.set_contents_from_file(encrypted_out) k.set_acl("private")
def main(): """ """ if len(sys.argv) != 2: print "Expected APPLICATION folder as input" sys.exit(0) path = sys.argv[1] zip_dir(path) with open("%s.zip" % path) as fh: with open("%s.pak" % path, "wb") as out_fh: encrypt(fh, out_fh, PASSWORD)
def main(): if len(sys.argv) != 2: print("Expected APPLICATION folder as input") sys.exit(1) path = sys.argv[1] zip_dir(path) zipfile = f"{path}.zip" pakfile = f"{path}.pak" with open(zipfile, "rb") as fh: with open(pakfile, "wb") as out_fh: encrypt(fh, out_fh, PASSWORD) if os.path.exists(zipfile): os.unlink(zipfile)
def backup(filename, destination="cloudfiles", **kwargs): conf = kwargs.get("conf", None) storage_backend = storage_backends[destination](conf) arcname = filename.split("/")[-1] #stored_filename = arcname + datetime.now().strftime("%Y%m%d%H%M%S") + ".tgz" # filename file name date stored_filename = arcname + ".tgz" log.instance.logger.info("Backup started localname=" + filename + " remotename=" + str(stored_filename)) password = kwargs.get("password") if conf is not None: # If the conf has been populated by using this as a module, set the password. password = conf.get("crypto_password") else: if not password: password = getpass("Password (blank to disable encryption): ") log.instance.logger.info("Compressing... " + str(filename)) out = tempfile.TemporaryFile() # with tarfile.open(fileobj=out, mode="w:gz") as tar: # tar.add(filename, arcname=arcname) tarz = tarfile.open(fileobj=out, mode="w:gz") tarz.add(filename, arcname=arcname) tarz.close() if password == "None" or password == "none": password = None if password: log.instance.logger.info("Encrypting... " + str(filename)) encrypted_out = tempfile.TemporaryFile() encrypt(out, encrypted_out, password) stored_filename += ".enc" out = encrypted_out log.instance.logger.info(" => Getting md5 for " + str(filename)) out.seek(0) md5 = str(storage_backend.return_md5_for_localfile(out)) log.instance.logger.info("Uploading... " + str(filename)) out.seek(0) if storage_backend.upload(stored_filename, out, md5): return True
def upload_handler(instance, file_obj): bucket = get_bucket(app.config['AWSID'], app.config['AWSKEY'], app.config['AWSBUCKET']) key = bucket.new_key(os.path.join(instance.parent,instance.filename)) if instance.get_mimetype(): key.set_metadata('Content-Type', instance.get_mimetype()) if request.form.get('password'): # we received a password, so will need to encrypt the file data # before sending it off to S3 password = request.form['password'] instance.encrypted = True output_buffer = StringIO() encrypt(file_obj, output_buffer, password) file_obj = output_buffer else: instance.encrypted = False file_obj.seek(0) key.set_contents_from_file(file_obj)
def backup(filename, destination="s3", **kwargs): log = kwargs.get("logger", app_logger) conf = kwargs.get("conf", None) storage_backend = storage_backends[destination](conf, log) log.info("Backing up " + filename) arcname = filename.split("/")[-1] out = tempfile.TemporaryFile() with tarfile.open(fileobj=out, mode="w:gz") as tar: tar.add(filename, arcname=arcname) password = kwargs.get("password") if not password: password = getpass() encrypted_out = StringIO() encrypt(out, encrypted_out, password) encrypted_out.seek(0) stored_filename = arcname + datetime.now().strftime("%Y%m%d") + ".tgz.enc" storage_backend.upload(stored_filename, encrypted_out)