Vitalus library

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

Bases: object

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
class job.Job(log_dir, destination, name, source, period)[source]

Bases: object

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]

Bases: Exception

Exception for target validity

Parameters:message (string) – Message
args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class job.Target(target)[source]

Bases: object

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
class rsyncjob.RsyncJob(log_dir, destination, name, source, period, snapshot, duration, keep, force, guid, filter)[source]

Bases: Vitalus.job.Job

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.