API

Vitalus.vitalus — Main class

class vitalus.Vitalus(log_path='~/.backup', log_rotation=30, force=False)[source]

This is the main class to declare and run backup tasks.

Params log_path:
 directory for logs and database
Params log_rotation:
 How many days logs are kept
Parameters:force – if True, do not perform timebase check.

All jobs will be run. :type force: bool

add_customjob(name, job, *args)[source]

Add a custom job.

Parameters:
  • name (string) – backup label
  • period (float) – min time (hours) between backups
  • job – object representing a job
  • args – arguments to initialize the job

Note

This is particularly useful to do not use the run() function implemented in RsyncJob. For instance, a git-annex repository can be synchronized by writting a proper class to use git-annex features.

add_rsyncjob(name, source, period=24, history=False, duration=50, keep=10, filter=None)[source]

Add a rsync job.

Parameters:
  • name (string) – backup label
  • source (string) – backup from...
  • destination (string) – backup to...
  • period (float) – min time (hours) between backups
  • history – Activate (True) or desactivate (False) snapshots

or perform a simple copy (None). :type history: bool or None :param duration: How many days snapshotss are kept :type duration: int :param keep: How many snapshots are (at least) kept :type keep: int :param filter: filters :type filter: tuple

Raises:ValueError – if destination if not set

Note

Filter syntax is the same of rsync. See “FILTER RULES” section in the rsync man page.

history: if set to True or False, the date is written in the path. This is a feature. It leaves you the possibility to switch on/off the history. If you don’t want the date in the path, set the value to None.

run()[source]

Run all jobs

set_destination(destination, guid=(None, None))[source]

Set the destination of the backup if uid or gid are None, files owner are not changed

Parameters:
  • destination (string) – destination path
  • guid (tuple) – (uid, gid) for destination
set_log_level(level='INFO')[source]

Set the logger level (INFO, CRITICAL, DEBUG, ERROR, FATAL)

Parameters:level (string) – Loger level

Vitalus.history — functions to determine files to delete

history.older(file_list, days=5)[source]

Return older files than “days”

Parameters:
  • file_list – list of files named in the format “%Y-%m-%d_%Hh%Mm%Ss”
  • days – files older than this value are old
Returns:

a sorted list of old files

history.older_keepmin(file_list, days=5, keep=10)[source]

Return older files in a list but keep a minium amount of files

Parameters:
  • file_list – list of files named in the format “%Y-%m-%d_%Hh%Mm%Ss”
  • days – files older than this value are old
  • keep – keep at least this number of files
Returns:

a sorted list of old files

Vitalus.rsyncjob

class rsyncjob.RsyncJob(log_dir, destination, name, source, period, snapshot, duration, keep, force, guid, filter)[source]

Class containing a rsync job

Parameters:
  • log_dir (string) – Log directory path
  • destination (string) – Destination path
  • name (string) – Job name
  • source (string) – Source path
  • period (float) – Min duration between two backups (in seconds)
  • snapshot (bool or None) – Activate (True) or desactivate (False) snapshots or simple (None) copy
  • duration (int) – How many days snapshots are kept
  • keep (int) – How many snapshots are (at least) kept
  • force (bool) – overide the timebase check, no min. duration.
  • guid (tuple) – (uid, gid) for destination
  • filter (list) – Rsync filters

Note

Source and destination path can be either real path or a ssh login joined to the path by a : character.

if uid or gid are None, files owner are not changed

run(uid=None, gid=None)[source]

Run the job.

Vitalus.job

class job.Job(log_dir, destination, name, source, period)[source]

Class containing a job

Parameters:
  • log_dir (string) – Log directory path
  • destination (string) – Destination path
  • name (string) – Job name
  • source (string) – Source path
  • period (float) – Min duration between two backups (in seconds)

Note

run(uid=None, gid=None)[source]

Run the job.

exception job.TARGETError(message='')[source]

Exception for target validity

Parameters:message (string) – Message
class job.Target(target)[source]

A target is a source or a destination. It can be a local directory or a remote one (SSH)

Parameters:target (string) – a target
check_availability()[source]

Check if the target is available For SSH host, it means it’s reachable

Raises:TARGETError – if not available
is_local()[source]

Check if the target is a directory

Returns:bool – True if it is a directory
is_ssh()[source]

Check if the target is a ‘SSH’ host

Returns:bool – True if it is a SSH host

Vitalus.utils

utils.compress(path)[source]

Compress the directory

utils.get_folder_size(path)[source]

Get the size of the content in path

utils.get_last_file(file_list)[source]

Return the more recent file in a list (in the format “%Y-%m-%d_%Hh%Mm%Ss”)

Parameters:file_list – list of files
Returns:filename
utils.get_older_files(file_list, days=5, keep=10)[source]

Deprecated. Use Vitalus.history.older_keepmin()

utils.r_chmod(path, mode)[source]

Equivalent to chmod -R mod path

Parameters:
  • path – path
  • mode – mode
utils.r_chown(path, uid, gid)[source]

Equivalent to chown -R uid:gid path

Parameters:
  • path – path
  • uid – user ID
  • gid – group ID