module filehelper.encrypted_backup

Inheritance diagram of pyquickhelper.filehelper.encrypted_backup

Short summary

module pyquickhelper.filehelper.encrypted_backup

Keeps an encrypted of personal data

source on GitHub

Classes

class

truncated documentation

EncryptedBackup

This class aims at keeping an encrypted and compressed backup of files. Every file is compressed and then encrypted …

EncryptedBackupError

raised by EncryptedBackup

Properties

property

truncated documentation

Mapping

returns the mapping

Methods

method

truncated documentation

__init__

constructor

compress

compress data

decompress

decompress data

enumerate_read_encrypt

enumerate pieces of files as bytes

iter_eligible_files

iterates on eligible file for transfering (if they have been modified)

load_mapping

retrieves existing mapping

retrieve

retrieve a backuped file

retrieve_all

retrieve all backuped files

start_transfering

starts transfering files to the remote website

transfer

transfer data

transfer_mapping

transfer the mapping

update_mapping

update the status of a file

update_status

update the status of a file

Documentation

Keeps an encrypted of personal data

source on GitHub

class pyquickhelper.filehelper.encrypted_backup.EncryptedBackup(key, file_tree_node, transfer_api, file_status, file_map, root_local=None, root_remote=None, filter_out=None, threshold_size=16777216, algo='AES', compression='lzma', fLOG=<function noLOG>)[source][source]

Bases: object

This class aims at keeping an encrypted and compressed backup of files. Every file is compressed and then encrypted before being uploaded to the remote location. Its name still contains the container but the file name is a hash. A

Encrypted and compressed backup

Here is an example which stores everything on hard drive. A second run only modifies files updated between the two processes. A modified file does not remove the previous version, it creates a new file. Example:

from pyquickhelper.loghelper import fLOG
from pyquickhelper.filehelper import FileTreeNode, EncryptedBackup
from pyensae.remote import TransferAPIFile

key_crypt = "crypt"

local = os.path.normpath(os.path.join(os.path.dirname(__file__), ".."))
this = os.path.normpath(os.path.dirname(__file__))
file_status=os.path.join(this, "backup_status.txt")
file_map=os.path.join(this, "backup_mapping.txt")

backup = True
if backup:
    # code to backup
    root = os.path.normpath(os.path.join(os.path.dirname(__file__)))
    api = TransferAPIFile("f:\\mycryptedbackup")
    ft = FileTreeNode(root, repository=True)
    enc = EncryptedBackup(
        key=key_crypt,
        file_tree_node=ft,
        transfer_api=api,
        root_local=local,
        file_status=file_status,
        file_map=file_map,
        fLOG=print)

    enc.start_transfering()

restore = not backup
if restore:
    # code to restore
    root = os.path.normpath(os.path.join(os.path.dirname(__file__)))
    api = TransferAPIFile("f:\\mycryptedbackup")
    enc = EncryptedBackup(
        key=key_crypt,
        file_tree_node=None,
        transfer_api=api,
        root_local=local,
        file_status=file_status,
        file_map=file_map,
        fLOG=print)

    dest=os.path.join(this, "_temp")
    enc.retrieve_all(dest)

source on GitHub

constructor

Parameters
  • key – key for encryption

  • file_tree_nodeFileTreeNode

  • transfer_apiTransferFTP

  • file_status – file keeping the status for each file (date, hash of the content for the last upload)

  • file_map – keep track of local filename and remote location

  • root_local – local root

  • root_remote – remote root

  • filter_out – regular expression to exclude some files, it can also be a function.

  • threshold_size – above that size, big files are split

  • algo – encrypting algorithm

  • compression – kind of compression 'lzma' or 'zip'

  • fLOG – logging function

source on GitHub

property Mapping[source]

returns the mapping

source on GitHub

__init__(key, file_tree_node, transfer_api, file_status, file_map, root_local=None, root_remote=None, filter_out=None, threshold_size=16777216, algo='AES', compression='lzma', fLOG=<function noLOG>)[source][source]

constructor

Parameters
  • key – key for encryption

  • file_tree_nodeFileTreeNode

  • transfer_apiTransferFTP

  • file_status – file keeping the status for each file (date, hash of the content for the last upload)

  • file_map – keep track of local filename and remote location

  • root_local – local root

  • root_remote – remote root

  • filter_out – regular expression to exclude some files, it can also be a function.

  • threshold_size – above that size, big files are split

  • algo – encrypting algorithm

  • compression – kind of compression 'lzma' or 'zip'

  • fLOG – logging function

source on GitHub

compress(data)[source][source]

compress data

Parameters

data – binary data

Returns

binary data

source on GitHub

decompress(data)[source][source]

decompress data

Parameters

data – binary data

Returns

binary data

source on GitHub

enumerate_read_encrypt(fullname)[source][source]

enumerate pieces of files as bytes

Parameters

fullname – fullname

Returns

iterator on chunk of data

source on GitHub

iter_eligible_files()[source][source]

iterates on eligible file for transfering (if they have been modified)

Returns

iterator on file name

source on GitHub

load_mapping()[source][source]

retrieves existing mapping

Returns

dictionary

source on GitHub

retrieve(path, filename=None, root=None)[source][source]

retrieve a backuped file

Parameters
  • path – path of the file to retrieve

  • filename – if not None, store the file into this file

  • root – if not None, store the file into root + path

Returns

filename or data

source on GitHub

retrieve_all(dest, regex=None)[source][source]

retrieve all backuped files

Parameters
  • dest – destination

  • regex – retrieve a subset matching the regular expression

Returns

list of restored files

source on GitHub

start_transfering()[source][source]

starts transfering files to the remote website

Returns

list of transferred FileInfo

Raises

FolderTransferFTPException – The class raises an exception (FolderTransferFTPException) if more than 5 issues happened.

source on GitHub

transfer(to, data)[source][source]

transfer data

Parameters
  • to – remote path

  • data – binary data

Returns

boolean

source on GitHub

transfer_mapping()[source][source]

transfer the mapping

source on GitHub

update_mapping(key, maps)[source][source]

update the status of a file

Parameters
  • key – key

  • maps – update the mapping

source on GitHub

update_status(file)[source][source]

update the status of a file

Parameters

file – filename

Returns

FileInfo

source on GitHub

exception pyquickhelper.filehelper.encrypted_backup.EncryptedBackupError[source][source]

Bases: Exception

raised by EncryptedBackup

source on GitHub