def backup_mediafiles(self, encrypt, compress):
        source_dir = self.get_source_dir()
        if not source_dir:
            print("No media source dir configured.")
            sys.exit(0)
        print("Backing up media files in %s" % source_dir)
        output_file = self.create_backup_file(
            source_dir,
            self.get_backup_basename(
                compress=compress
            ),
            compress=compress
        )

        if encrypt:
            encrypted_file = utils.encrypt_file(output_file)
            output_file = encrypted_file

        print("  Backup tempfile created: %s (%s)" % (output_file.name, utils.handle_size(output_file)))
        print("  Writing file to %s: %s" % (self.storage.name, self.storage.backup_dir))
        self.storage.write_file(
            output_file,
            self.get_backup_basename(
                compress=compress)
        )
Beispiel #2
0
    def save_new_backup(self, database_name):
        """ Save a new backup file. """
        print("Backing Up Database: %s" % database_name)

        temp_dir = tempfile.mkdtemp(prefix='backup')
        try:
            backup_extension = self.backup_extension or self.dbcommands.settings.extension

            backup_file = os.path.join(
                temp_dir,
                utils.generate_backup_filename(database_name, self.servername, backup_extension)
            )

            with open(backup_file, 'wb') as f:
                self.dbcommands.run_backup_commands(f)

            if self.compress:
                backup_file = self.compress_file(backup_file)

            if self.encrypt:
                backup_file = utils.encrypt_file(backup_file)

            print("  Backup tempfile created: %s" % (utils.handle_size(backup_file)))
            print("  Writing file to %s: %s" % (self.storage.name, backup_file))

            self.storage.write_file(backup_file)
        finally:
            shutil.rmtree(temp_dir)
    def backup_mediafiles(self, encrypt):
        source_dir = self.get_source_dir()
        if not source_dir:
            print("No media source dir configured.")
            sys.exit(0)

        temp_dir = tempfile.mkdtemp(prefix='backup')
        try:
            print("Backing up media files in %s" % source_dir)

            output_file = os.path.join(temp_dir, self.get_backup_basename())

            self.create_backup_file(source_dir, output_file)

            if encrypt:
                encrypted_file = utils.encrypt_file(output_file)

                # remove previous file to save disk space
                os.remove(output_file)

                output_file = encrypted_file

            print("  Backup tempfile created: %s (%s)" % (output_file, utils.handle_size(output_file)))
            print("  Writing file to %s: %s" % (self.storage.name, output_file))
            self.storage.write_file(output_file)
        finally:
            shutil.rmtree(temp_dir)
Beispiel #4
0
 def test_decrypt(self, *args):
     self.command.path = None
     self.command.decrypt = True
     encrypted_file, self.command.filename = utils.encrypt_file(
         get_dump(), get_dump_name())
     HANDLED_FILES['written_files'].append(
         (self.command.filename, encrypted_file))
     self.command._restore_backup()
 def test_decrypt(self, *args):
     self.command.path = None
     self.command.decrypt = True
     encrypted_file, self.command.filename = utils.encrypt_file(get_dump(), get_dump_name())
     HANDLED_FILES['written_files'].append(
         (self.command.filename, encrypted_file)
     )
     self.command._restore_backup()
Beispiel #6
0
def backup_database(database_name):
    connector = get_connector('default')
    filename = connector.generate_filename()
    outputfile = connector.create_dump()
    if GPG_RECIPIENT:
        outputfile, filename = utils.encrypt_file(outputfile, filename)
    compressed_file, filename = utils.compress_file(outputfile, filename)
    outputfile = compressed_file
    outputfile.seek(0)
    return outputfile, filename
Beispiel #7
0
 def save_new_backup(self, database, database_name):
     """ Save a new backup file. """
     print("Backing Up Database: %s" % database['NAME'])
     filename = self.dbcommands.filename(self.servername)
     outputfile = tempfile.SpooledTemporaryFile(max_size=10 * 1024 * 1024)
     self.dbcommands.run_backup_commands(outputfile)
     if self.compress:
         compressed_file = self.compress_file(outputfile)
         outputfile.close()
         outputfile = compressed_file
     if self.encrypt:
         encrypted_file = utils.encrypt_file(outputfile)
         outputfile = encrypted_file
     print("  Backup tempfile created: %s" % (utils.handle_size(outputfile)))
     print("  Writing file to %s: %s, filename: %s" % (self.storage.name, self.storage.backup_dir, filename))
     self.storage.write_file(outputfile, filename)
 def save_new_backup(self, database, database_name):
     """ Save a new backup file. """
     print("Backing Up Database: %s" % database['NAME'])
     filename = self.dbcommands.filename(self.servername)
     outputfile = tempfile.SpooledTemporaryFile(max_size=10 * 1024 * 1024)
     self.dbcommands.run_backup_commands(outputfile)
     if self.compress:
         compressed_file = self.compress_file(outputfile)
         outputfile.close()
         outputfile = compressed_file
     if self.encrypt:
         encrypted_file = utils.encrypt_file(outputfile)
         outputfile = encrypted_file
     print("  Backup tempfile created: %s" % (utils.handle_size(outputfile)))
     print("  Writing file to %s: %s, filename: %s" % (self.storage.name, self.storage.backup_dir, filename))
     self.storage.write_file(outputfile, filename)
    def backup_mediafiles(self, encrypt):
        source_dir = self.get_source_dir()
        if not source_dir:
            print("No media source dir configured.")
            sys.exit(0)
        print("Backing up media files in %s" % source_dir)
        output_file = self.create_backup_file(source_dir,
                                              self.get_backup_basename())

        if encrypt:
            encrypted_file = utils.encrypt_file(output_file)
            output_file = encrypted_file

        print("  Backup tempfile created: %s (%s)" %
              (output_file.name, utils.handle_size(output_file)))
        print("  Writing file to %s: %s" %
              (self.storage.name, self.storage.backup_dir))
        self.storage.write_file(output_file, self.get_backup_basename())
Beispiel #10
0
 def save_new_backup(self, database, database_name):
     """ Save a new backup file. """
     print("Backing Up Database: %s" % database['NAME'])
     filename = '{servername}-{database_name}-{timestamp}.{backup_extension}'.format(
             servername=self.servername,
             database_name=database_name,
             timestamp=time.strftime("%Y%m%d-%H%M%S"),
             backup_extension=self.backup_extension
         )
     outputfile = tempfile.SpooledTemporaryFile(max_size=10 * 1024 * 1024)
     self.dbcommands.run_backup_commands(outputfile)
     if self.compress:
         compressed_file = self.compress_file(outputfile)
         outputfile.close()
         outputfile = compressed_file
     if self.encrypt:
         encrypted_file = utils.encrypt_file(outputfile)
         outputfile = encrypted_file
     print("  Backup tempfile created: %s" % (utils.handle_size(outputfile)))
     print("  Writing file to %s: %s, filename: %s" % (self.storage.name, self.storage.backup_dir, filename))
     self.storage.write_file(outputfile, filename)
Beispiel #11
0
    def backup_mediafiles(self, encrypt, compress):
        source_dir = self.get_source_dir()
        if not source_dir:
            self.stderr.write("No media source dir configured.")
            sys.exit(0)
        self.log("Backing up media files in %s" % source_dir, 1)
        filename = self.get_backup_basename(compress=compress)
        output_file = self.create_backup_file(source_dir,
                                              filename,
                                              compress=compress)

        if encrypt:
            encrypted_file = utils.encrypt_file(output_file, filename)
            output_file, filename = encrypted_file

        self.log(
            "  Backup tempfile created: %s (%s)" %
            (filename, utils.handle_size(output_file)), 1)
        self.log(
            "  Writing file to %s: %s" %
            (self.storage.name, self.storage.backup_dir), 1)
        self.storage.write_file(output_file,
                                self.get_backup_basename(compress=compress))
 def test_func(self, *args):
     with open(self.path) as fd:
         encrypted_file, filename = utils.encrypt_file(inputfile=fd,
                                                       filename='foo.txt')
     encrypted_file.seek(0)
     self.assertTrue(encrypted_file.read())
 def test_func(self, *args):
     with open(self.path) as fd:
         compressed_file, filename = utils.encrypt_file(inputfile=fd,
                                                        filename='foo.txt')
Beispiel #14
0
 def test_func(self, *args):
     with open(self.path) as fd:
         compressed_file, filename = utils.encrypt_file(inputfile=fd,
                                                        filename='foo.txt')
Beispiel #15
0
 def test_func(self, *args):
     with open(self.path) as fd:
         encrypted_file, filename = utils.encrypt_file(inputfile=fd,
                                                       filename='foo.txt')
     encrypted_file.seek(0)
     self.assertTrue(encrypted_file.read())