module filehelper.encrypted_backup
¶
Short summary¶
module pyquickhelper.filehelper.encrypted_backup
Keeps an encrypted of personal data
Classes¶
class |
truncated documentation |
---|---|
This class aims at keeping an encrypted and compressed backup of files. Every file is compressed and then encrypted … |
|
raised by |
Properties¶
property |
truncated documentation |
---|---|
returns the mapping |
Methods¶
method |
truncated documentation |
---|---|
constructor |
|
compress data |
|
decompress data |
|
enumerate pieces of files as bytes |
|
iterates on eligible file for transfering (if they have been modified) |
|
retrieves existing mapping |
|
retrieve a backuped file |
|
retrieve all backuped files |
|
starts transfering files to the remote website |
|
transfer data |
|
transfer the mapping |
|
update the status of a file |
|
update the status of a file |
Documentation¶
Keeps an encrypted of personal data
- 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]¶
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)
constructor
- Parameters:
key – key for encryption
file_tree_node –
FileTreeNode
transfer_api –
TransferFTP
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
- __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]¶
constructor
- Parameters:
key – key for encryption
file_tree_node –
FileTreeNode
transfer_api –
TransferFTP
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
- enumerate_read_encrypt(fullname)[source]¶
enumerate pieces of files as bytes
- Parameters:
fullname – fullname
- Returns:
iterator on chunk of data
- iter_eligible_files()[source]¶
iterates on eligible file for transfering (if they have been modified)
- Returns:
iterator on file name
- retrieve(path, filename=None, root=None)[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
- retrieve_all(dest, regex=None)[source]¶
retrieve all backuped files
- Parameters:
dest – destination
regex – retrieve a subset matching the regular expression
- Returns:
list of restored files
- start_transfering()[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.
- transfer(to, data)[source]¶
transfer data
- Parameters:
to – remote path
data – binary data
- Returns:
boolean
- update_mapping(key, maps)[source]¶
update the status of a file
- Parameters:
key – key
maps – update the mapping
- exception pyquickhelper.filehelper.encrypted_backup.EncryptedBackupError[source]¶
Bases:
Exception
raised by
EncryptedBackup