Bakthat API¶
Bakthat¶
These functions are called when using bakthat in command line mode and are the foundation of the bakthat module.
backup¶
-
bakthat.
backup
(filename='/var/build/user_builds/bakthat/checkouts/latest/docs', destination=None, profile='default', config='/home/docs/.bakthat.yml', prompt='yes', tags=[], key=None, exclude_file=None, s3_reduced_redundancy=False, **kwargs)¶ Perform backup.
Parameters: - filename (str) – File/directory to backup.
- destination (str) – s3|glacier|swift
- prompt (str) – Disable password promp, disable encryption, only useful when using bakthat in command line mode.
- tags (str or list) – Tags either in a str space separated, either directly a list of str (if calling from Python).
- password (str) – Password, empty string to disable encryption.
- conf (dict) – Override/set AWS configuration.
- custom_filename (str) – Override the original filename (only in metadata)
Return type: dict
Returns: A dict containing the following keys: stored_filename, size, metadata, backend and filename.
restore¶
-
bakthat.
restore
(filename, destination=None, profile='default', config='/home/docs/.bakthat.yml', **kwargs)¶ Restore backup in the current working directory.
Parameters: - filename (str) – File/directory to backup.
- destination (str) – s3|glacier|swift
- profile (str) – Profile name (default by default).
- conf (dict) – Override/set AWS configuration.
Return type: bool
Returns: True if successful.
info¶
show¶
-
bakthat.
show
(query='', destination='', tags='', profile='default', config='/home/docs/.bakthat.yml')¶
delete¶
-
bakthat.
delete
(filename, destination=None, profile='default', config='/home/docs/.bakthat.yml', **kwargs)¶ Delete a backup.
Parameters: - filename (str) – stored filename to delete.
- destination (str) – glacier|s3|swift
- profile (str) – Profile name (default by default).
- conf (dict) – A dict with a custom configuration.
- conf – Override/set AWS configuration.
Return type: bool
Returns: True if the file is deleted.
delete_older_than¶
-
bakthat.
delete_older_than
(filename, interval, profile='default', config='/home/docs/.bakthat.yml', destination=None, **kwargs)¶ Delete backups matching the given filename older than the given interval string.
Parameters: - filename (str) – File/directory name.
- interval (str) – Interval string like 1M, 1W, 1M3W4h2s... (s => seconds, m => minutes, h => hours, D => days, W => weeks, M => months, Y => Years).
- destination (str) – glacier|s3|swift
- conf (dict) – Override/set AWS configuration.
Return type: list
Returns: A list containing the deleted keys (S3) or archives (Glacier).
rotate_backups¶
-
bakthat.
rotate_backups
(filename, destination=None, profile='default', config='/home/docs/.bakthat.yml', **kwargs)¶ Rotate backup using grandfather-father-son rotation scheme.
Parameters: - filename (str) – File/directory name.
- destination (str) – s3|glacier|swift
- conf (dict) – Override/set AWS configuration.
- days (int) – Number of days to keep.
- weeks (int) – Number of weeks to keep.
- months (int) – Number of months to keep.
- first_week_day (str) – First week day (to calculate wich weekly backup keep, saturday by default).
Return type: list
Returns: A list containing the deleted keys (S3) or archives (Glacier).
Backends¶
BakthatBackend¶
-
class
bakthat.backends.
BakthatBackend
(conf={}, profile='default')¶ Handle Configuration for Backends.
The profile is only useful when no conf is None.
Parameters: - conf (dict) – Custom configuration
- profile (str) – Profile name
GlacierBackend¶
-
class
bakthat.backends.
GlacierBackend
(conf={}, profile='default')¶ Backend to handle Glacier upload/download.
-
backup_inventory
()¶ Backup the local inventory from shelve as a json string to S3.
-
delete_job
(filename)¶ Delete the job entry for the filename.
Parameters: filename (str) – Stored filename.
-
download
(keyname, job_check=False)¶ Initiate a Job, check its status, and download the archive if it’s completed.
-
get_job_id
(filename)¶ Get the job_id corresponding to the filename.
Parameters: filename (str) – Stored filename.
-
load_archives_from_s3
()¶ Fetch latest inventory backup from S3.
-
restore_inventory
()¶ Restore inventory from S3 to local shelve.
-
retrieve_archive
(archive_id, jobid)¶ Initiate a job to retrieve Galcier archive or download archive.
-
retrieve_inventory
(jobid)¶ Initiate a job to retrieve Galcier inventory or output inventory.
-
S3Backend¶
SwiftBackend¶
Helper¶
BakHelper¶
-
class
bakthat.helper.
BakHelper
(backup_name, **kwargs)¶ Helper that makes building scripts with bakthat better faster stronger.
Designed to be used as a context manager.
Parameters: - backup_name (str) – Backup name also the prefix for the created temporary directory.
- destination (str) – Destination (glacier|s3)
- password (str) – Password (Empty string to disable encryption, disabled by default)
- profile (str) – Profile name, only valid if no custom conf is provided
- conf (dict) – Override profiles configuration
- tags (list) – List of tags
-
backup
(filename=None, **kwargs)¶ Perform backup.
Parameters: - filename (str) – File/directory to backup.
- password (str) – Override already set password.
- destination (str) – Override already set destination.
- tags (list) – Tags list
- profile (str) – Profile name
- conf (dict) – Override profiles configuration
Return type: dict
Returns: A dict containing the following keys: stored_filename, size, metadata and filename.
-
delete_older_than
(filename=None, interval=None, **kwargs)¶ Delete backups older than the given interval string.
Parameters: - filename (str) – File/directory name.
- interval (str) – Interval string like 1M, 1W, 1M3W4h2s... (s => seconds, m => minutes, h => hours, D => days, W => weeks, M => months, Y => Years).
- destination (str) – Override already set destination.
- profile (str) – Profile name
- conf (dict) – Override profiles configuration
Return type: list
Returns: A list containing the deleted keys (S3) or archives (Glacier).
-
enable_sync
(api_url, auth=None)¶ Enable synchronization with
bakthat.sync.BakSyncer
(optional).Parameters: - api_url (str) – Base API URL.
- auth (tuple) – Optional, tuple/list (username, password) for API authentication.
-
restore
(filename, **kwargs)¶ Restore backup in the current working directory.
Parameters: - filename (str) – File/directory to backup.
- password (str) – Override already set password.
- destination (str) – Override already set destination.
- profile (str) – Profile name
- conf (dict) – Override profiles configuration
Return type: bool
Returns: True if successful.
-
rotate
(filename=None, **kwargs)¶ Rotate backup using grandfather-father-son rotation scheme.
Parameters: - filename (str) – File/directory name.
- destination (str) – Override already set destination.
- profile (str) – Profile name
- conf (dict) – Override profiles configuration
Return type: list
Returns: A list containing the deleted keys (S3) or archives (Glacier).
-
sync
()¶ Shortcut for calling BakSyncer.
KeyValue¶
-
class
bakthat.helper.
KeyValue
(conf={}, profile='default')¶ A Key Value store to store/retrieve object/string on S3.
Data is gzipped and json encoded before uploading, compression can be disabled.
-
delete_key
(keyname)¶ Delete the given key.
Parameters: keyname (str) – Key name
-
get_key
(keyname, **kwargs)¶ Return the object stored under keyname.
Parameters: - keyname (str) – Key name
- default (str) – Default value if key name does not exist, None by default
Return type: str
Returns: The key content as string, or default value.
-
get_key_url
(keyname, expires_in, method='GET')¶ Generate a URL for the keyname object.
Be careful, the response is JSON encoded.
Parameters: - keyname (str) – Key name
- expires_in (int) – Number of the second before the expiration of the link
- method (str) – HTTP method for access
Rtype str: Returns: The URL to download the content of the given keyname
-
set_key
(keyname, value, **kwargs)¶ Store a string as keyname in S3.
Parameters: - keyname (str) – Key name
- value (bool) – Value to save, will be json encoded.
- compress – Compress content with gzip, True by default
-
Sync¶
BakSyncer¶
-
class
bakthat.sync.
BakSyncer
(conf=None)¶ Helper to synchronize change on a backup set via a REST API.
No sensitive information is transmitted except (you should be using https): - API user/password - a hash (hashlib.sha512) of your access_key concatened with
your s3_bucket or glacier_vault, to be able to sync multiple client with the same configuration stored as metadata for each bakckupyy.Parameters: conf (dict) – Config (url, username, password) -
register
()¶ Register/create the current host on the remote server if not already registered.
-
sync
()¶ Draft for implementing bakthat clients (hosts) backups data synchronization.
Synchronize Bakthat sqlite database via a HTTP POST request.
Backups are never really deleted from sqlite database, we just update the is_deleted key.
It sends the last server sync timestamp along with data updated since last sync. Then the server return backups that have been updated on the server since last sync.
On both sides, backups are either created if they don’t exists or updated if the incoming version is newer.
-
sync_auto
()¶ Trigger sync if autosync is enabled.
-
bakmanager_hook¶
-
bakthat.sync.
bakmanager_hook
(conf, backup_data, key=None)¶ First version of a hook for monitoring periodic backups with BakManager (https://bakmanager.io).
Parameters: - conf (dict) – Current profile config
- backup_data (dict) – Backup data (size)
- key (str) – Periodic backup identifier
Utils¶
-
bakthat.utils.
_timedelta_total_seconds
(td)¶ Python 2.6 backward compatibility function for timedelta.total_seconds.
Parameters: td (timedelta object) – timedelta object Return type: float Returns: The total number of seconds for the given timedelta object.
-
bakthat.utils.
_interval_string_to_seconds
(interval_string)¶ Convert internal string like 1M, 1Y3M, 3W to seconds.
Parameters: interval_string (str) – Interval string like 1M, 1W, 1M3W4h2s... (s => seconds, m => minutes, h => hours, D => days, W => weeks, M => months, Y => Years). Return type: int Returns: The conversion in seconds of interval_string.
Models¶
-
class
bakthat.models.
Backups
(*args, **kwargs)¶ Backups Model.
-
class
bakthat.models.
Inventory
(*args, **kwargs)¶ Filename => archive_id mapping for glacier archives.
-
class
bakthat.models.
Jobs
(*args, **kwargs)¶ filename => job_id mapping for glacier archives.
-
classmethod
get_job_id
(filename)¶ Try to retrieve the job id for a filename.
Parameters: filename (str) – Filename Return type: str Returns: Job Id for the given filename
-
classmethod
update_job_id
(filename, job_id)¶ Update job_id for the given filename.
Parameters: - filename (str) – Filename
- job_id (str) – New job_id
Returns: None
-
classmethod
-
class
bakthat.models.
Config
(*args, **kwargs)¶ key => value config store.