Api Docs¶
Implement backup, verify, restore for bun.
-
class
bun.backup.
Bun
(ctx, timestamp)[source]¶ Backup path(s) based on configuration.
-
backup
(target)[source]¶ Foreach target spec, backup the specified paths (if they exist). :param target: a list of one or more target spec names
-
check
(directory)[source]¶ Foreach tarball in directory verify check sums
Parameters: directory – directory containing tarballs to validate checksums of.
-
check_sum
(spec_name)[source]¶ return a shell command to create the specified checksum of the created tarball. :param spec_name: use this as the start of the tarball name :return: the checksum pipeline command to create the checksum file
-
compress
(output='-')[source]¶ Generate the (optional) compress command as part of the backup pipeline :param output: optionally specify the output directly - defaults to stdout (‘-‘) :return: the compress command
-
only_existing
(paths)[source]¶ Return a list of elements from paths which exist on the filesystem (respects start_dir).
-
paths
(target)[source]¶ generator which yields the list of paths to process :param target: specifies the list of spec sets to return :return: (yield) a tuple: the (spec_name, path(s) list) to be backed up
-
pipeline
(spec_name, paths)[source]¶ return a shell command to backup the directory tree at path :param spec_name: use this as the start of the tarball name :param paths: list of paths to backup in one go :return: the tar pipeline command to tar’up the directory tree under path
-
pretend
(target)[source]¶ As per backup, but don’t check if paths exist, and only echo the tar command (not run it) :param target: is a list of one or more target spec names
-
redirect
(spec_name, extra_suffix='')[source]¶ Generates the shell output redirect to create a tarball (or checksum of that tarball) :param spec_name: unique name prefix for a tarball/checksum file :param extra_suffix: optional suffix to add to the generated redirect/path :return: a redirect to path string suitable to store the generated tarball
-
restore
(location, target)[source]¶ extract the tarballs belonging to target in bun.backup_dir to location :param location: is the point where the tarballs will be extracted to :param target: is the spec name of the target(s) to extract
-
tar
(paths, output='-')[source]¶ Generate a tar command :param paths: list of paths to backup in one go :param output: optionally specify the output directly - defaults to stdout (‘-‘) :return: the tar command
-
tarball
(spec_name, extra_suffix='')[source]¶ Return the full path name of a tarball (or checksum of that tarball) based on spec_name :param spec_name: unique name prefix for a tarball/checksum file :param extra_suffix: optional suffix to add to the generated path name :return: a (string) tarball file name (fully qualified)
-
Implements configuration discovery for bun
-
bun.config.
add_packages
(bun_config, directory)[source]¶ if directory exists then merge all configuration into the bun_config dict
Parameters: - bun_config – existing dict config to merge new config into
- directory – directory which holds config to merge
Returns: merged dict of the original config plus config from directory
-
bun.config.
settings
()[source]¶ generate a consolidated set of configuration for bun - if BUN_CONFIG_DIR is set then only read configuration from there; otherwise read config from the directory /etc/bun and the file /etc/oam/conf.d/bun.yaml (if it exists)
Returns: a dict holding bun configuration
-
bun.config.
config
()[source]¶ dump configuration in effect to the console
Parameters: ctx – invoke context
Implementation of builtin defaults for bun
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | DEFAULT_CONFIG = {
'bun': {
'backup_dir': '/backup', # location we backup to
'checksum': 'sha256sum', # checksum program to use - leave empty for no checksum generation
'compress': 'xz -9', # compression command to use - leave empty for no compression; also see suffix
'default': ['homes'], # default 'spec set(s)' to backup; see: spec dict later on
'nice': 'nice ionice -c3', # nice'ness to use - leave empty for no nice'ness
'suffix': 'xz', # add this suffix to the generated tarball; see compress program earlier
'start_dir': '/', # paths to backup are relative to this dir
'tar_opts': [ # options to pass to tar
'--exclude-caches',
'--exclude-vcs',
'--exclude-vcs-ignores',
'--one-file-system'
],
'timespec': '%Y%m%d-%H%M%S', # alt: '%Y%m%d'
'spec': { # directory sets that can be backed up
'homes': [ # unique token to identify the set (the reserved token 'all' means all sets)
'home', # list of directories/files to backup relative to the start_dir
'root'
]
}
},
'run': { # invoke default overrides
'echo': True
}
}
|
Implement script entry point for bun.