diff options
author | Joerg Steffens <joerg.steffens@bareos.com> | 2021-12-22 19:52:51 +0300 |
---|---|---|
committer | Joerg Steffens <joerg.steffens@bareos.com> | 2022-04-06 23:26:00 +0300 |
commit | 0dccab05ecebffa839409634731e4423f5e50205 (patch) | |
tree | 8c8e67f2ea425aec40088458e94e22147c099ba8 /contrib | |
parent | 87262c6b3c5723ca1ddfc547d1f988a1293cd860 (diff) |
contrib bareos_tasks: adapted for Bareos >= 20
... and adapted it to Python 3.
Uses sudo instead of subprocess preexec_fn function,
which is not supported in subprocessors in Python 3.
Diffstat (limited to 'contrib')
15 files changed, 204 insertions, 169 deletions
diff --git a/contrib/fd-plugins/bareos_tasks/BareosFdTaskClass.py b/contrib/fd-plugins/bareos_tasks/BareosFdTaskClass.py index 154e1d0c1..24af55379 100644 --- a/contrib/fd-plugins/bareos_tasks/BareosFdTaskClass.py +++ b/contrib/fd-plugins/bareos_tasks/BareosFdTaskClass.py @@ -19,12 +19,12 @@ import os import subprocess -from StringIO import StringIO from fcntl import fcntl, F_GETFL, F_SETFL from pwd import getpwnam +from io import BytesIO #import bareosfd -from bareosfd import JobMessage, DebugMessage, StatPacket, GetValue, bRCs, bIOPS, bJobMessageType, bFileType, bVariable, M_ERROR, M_INFO +from bareosfd import JobMessage, DebugMessage, StatPacket, GetValue, bRCs, bIOPS, bJobMessageType, bFileType, bVariable, bVarType, M_ERROR, M_INFO from BareosFdPluginBaseclass import BareosFdPluginBaseclass @@ -94,7 +94,7 @@ class Task(object): return 0 -class TaskStringIO(Task): +class TaskIO(Task): file_extension = 'log' def __init__(self, task_name, data): @@ -105,9 +105,8 @@ class TaskStringIO(Task): self.data.seek(0) def task_read(self, buf): - chunk = self.data.read(len(buf)) - buf[:len(chunk)] = chunk - return len(chunk) + written = self.data.readinto(buf) + return written class TaskProcess(Task): @@ -117,7 +116,7 @@ class TaskProcess(Task): command = list() use_stdout = True use_stderr = True - stderr_buffer = StringIO() + stderr_buffer = BytesIO() def get_details(self): sep = ' ' @@ -126,24 +125,31 @@ class TaskProcess(Task): def get_next_tasks(self): tasks = list() if self.use_stderr: - tasks.append(TaskStringIO(self.get_name() + '-stderr', self.stderr_buffer)) + tasks.append(TaskIO(self.get_name() + '-stderr', self.stderr_buffer)) return tasks - def pre_run_execute(self): - if self.run_as_user: - item = getpwnam(self.run_as_user) - os.chdir(item.pw_dir) - os.setgid(item.pw_gid) - os.setuid(item.pw_uid) + #def pre_run_execute(self): + #if self.run_as_user: + #item = getpwnam(self.run_as_user) + #os.chdir(item.pw_dir) + #os.setgid(item.pw_gid) + #os.setuid(item.pw_uid) - for key, value in self.run_environ.items(): - os.environ[key] = value + #for key, value in self.run_environ.items(): + #os.environ[key] = value def execute_command(self, command): + # previous version did use the subprocess parameter + # preexec_fn=self.pre_run_execute, + # however, this is no longer supported in subinterpreters: + # RuntimeError: preexec_fn not supported within subinterpreters + # Therefore "sudo" is used. + sudo = [] + if self.run_as_user: + sudo = [ "sudo", "-u", self.run_as_user ] try: - return subprocess.check_output(command, shell=False, bufsize=-1, - preexec_fn=self.pre_run_execute) - except (subprocess.CalledProcessError, OSError, ValueError), e: + return subprocess.check_output(sudo + command, shell=False, bufsize=-1) + except (subprocess.CalledProcessError, OSError, ValueError) as e: raise TaskException(e) def pool(self): @@ -154,14 +160,22 @@ class TaskProcess(Task): pass def task_open(self): + # previous version did use the subprocess parameter + # preexec_fn=self.pre_run_execute, + # however, this is no longer supported in subinterpreters: + # RuntimeError: preexec_fn not supported within subinterpreters + # Therefore "sudo" is used. + sudo = [] + if self.run_as_user: + sudo = [ "sudo", "-u", self.run_as_user ] try: - self.process = subprocess.Popen(self.command, shell=False, bufsize=-1, + self.process = subprocess.Popen(sudo + self.command, shell=False, bufsize=-1, stdout=subprocess.PIPE if self.use_stdout else None, - stderr=subprocess.PIPE if self.use_stderr else None, - preexec_fn=self.pre_run_execute) + stderr=subprocess.PIPE if self.use_stderr else None) + #preexec_fn=self.pre_run_execute) if self.use_stderr: fcntl(self.process.stderr, F_SETFL, fcntl(self.process.stderr, F_GETFL) | os.O_NONBLOCK) - except (subprocess.CalledProcessError, OSError, ValueError), e: + except (subprocess.CalledProcessError, OSError, ValueError) as e: raise TaskException('invalid command: {0} {1}'.format(self.command, e)) def task_read(self, buf): @@ -169,7 +183,7 @@ class TaskProcess(Task): raise TaskException('pipe closed') try: return self.process.stdout.readinto(buf) - except IOError, e: + except IOError as e: raise TaskException(e) def task_wait(self): @@ -210,7 +224,7 @@ class TaskProcessFIFO(TaskProcess): try: return self.fifo.readinto(buf) - except IOError, e: + except IOError as e: raise TaskException(e) def task_close(self): @@ -260,23 +274,23 @@ class BareosFdTaskClass(BareosFdPluginBaseclass): def parse_plugin_definition(self, plugin_def): BareosFdPluginBaseclass.parse_plugin_definition(self, plugin_def) - self.job_type = GetValue(bVariable['bVarType']) + self.job_type = GetValue(bVarType) self.config = PluginConfig(**self.options) self.folder = self.config.get('folder', '@{0}'.format(self.plugin_name.upper())) try: self.prepare_tasks() except TaskException as e: self.job_message(M_ERROR, str(e)) - return bRCs['bRC_Error'] + return bRCs[b'bRC_Error'] self.debug_message('{0} tasks created'.format(len(self.tasks))) - return bRCs['bRC_OK'] + return bRCs[b'bRC_OK'] def start_backup_file(self, save_pkt): if not len(self.tasks): - self.job_message(bJobMessageType['M_WARNING'], 'no tasks defined') - return bRCs['bRC_Skip'] + self.job_message(bJobMessageType[b'M_WARNING'], 'no tasks defined') + return bRCs[b'bRC_Skip'] self.task = self.tasks.pop() stat_pkt = StatPacket() @@ -284,52 +298,52 @@ class BareosFdTaskClass(BareosFdPluginBaseclass): stat_pkt.st_blksize = self.task.get_block_size() save_pkt.statp = stat_pkt save_pkt.fname = os.path.join(self.folder, self.task.get_filename()) - save_pkt.type = bFileType['FT_REG'] + save_pkt.type = bFileType[b'FT_REG'] - return bRCs['bRC_OK'] + return bRCs[b'bRC_OK'] def plugin_io(self, iop): if self.job_type == bJobType['BACKUP']: - if iop.func == bIOPS['IO_OPEN']: + if iop.func == bIOPS[b'IO_OPEN']: try: - self.job_message(bJobMessageType['M_INFO'], '{0} started'.format(self.task.get_name())) + self.job_message(bJobMessageType[b'M_INFO'], '{0} started'.format(self.task.get_name())) self.task.task_pool() self.task.task_open() - except TaskException, e: - self.job_message(bJobMessageType['M_ERROR'], '{0} {1}'.format(self.task.get_name(), e)) + except TaskException as e: + self.job_message(bJobMessageType[b'M_ERROR'], '{0} {1}'.format(self.task.get_name(), e)) return bRCs['bRC_Error'] - return bRCs['bRC_OK'] + return bRCs[b'bRC_OK'] - elif iop.func == bIOPS['IO_CLOSE']: + elif iop.func == bIOPS[b'IO_CLOSE']: try: - self.job_message(bJobMessageType['M_INFO'], '{0} done'.format(self.task.get_name())) + self.job_message(bJobMessageType[b'M_INFO'], '{0} done'.format(self.task.get_name())) self.task.task_pool() self.task.task_close() - except TaskException, e: - self.job_message(bJobMessageType['M_ERROR'], '{0} {1}'.format(self.task.get_name(), e)) + except TaskException as e: + self.job_message(bJobMessageType[b'M_ERROR'], '{0} {1}'.format(self.task.get_name(), e)) return bRCs['bRC_Error'] - return bRCs['bRC_OK'] + return bRCs[b'bRC_OK'] - elif iop.func == bIOPS['IO_READ']: + elif iop.func == bIOPS[b'IO_READ']: try: self.task.task_pool() iop.io_errno = 0 iop.buf = bytearray(iop.count) iop.status = self.task.task_read(iop.buf) - except TaskException, e: - self.job_message(bJobMessageType['M_ERROR'], '{0} {1}'.format(self.task.get_name(), e)) + except TaskException as e: + self.job_message(bJobMessageType[b'M_ERROR'], '{0} {1}'.format(self.task.get_name(), e)) return bRCs['bRC_Error'] - return bRCs['bRC_OK'] + return bRCs[b'bRC_OK'] - return super(BareosFdTaskClass).plugin_io(self, iop) + return super(BareosFdTaskClass, self).plugin_io(iop) def end_backup_file(self): result = self.task.task_wait() if result: - self.job_message(bJobMessageType['M_ERROR'], '{0} {1}'.format(self.task.get_details(), result)) - return bRCs['bRC_Error'] + self.job_message(bJobMessageType[b'M_ERROR'], '{0} {1}'.format(self.task.get_details(), result)) + return bRCs[b'bRC_Error'] self.tasks.extend(self.task.get_next_tasks()) - return bRCs['bRC_More'] if len(self.tasks) else bRCs['bRC_OK'] + return bRCs[b'bRC_More'] if len(self.tasks) else bRCs[b'bRC_OK'] diff --git a/contrib/fd-plugins/bareos_tasks/mysql/BareosFdMySQLClass.py b/contrib/fd-plugins/bareos_tasks/mysql/BareosFdMySQLClass.py index 5146a6f16..1bd20b877 100644 --- a/contrib/fd-plugins/bareos_tasks/mysql/BareosFdMySQLClass.py +++ b/contrib/fd-plugins/bareos_tasks/mysql/BareosFdMySQLClass.py @@ -19,7 +19,7 @@ import shlex -from BareosFdTaskClass import TaskProcess, BareosFdTaskClass +from bareos_tasks.BareosFdTaskClass import TaskProcess, BareosFdTaskClass class TaskQueryDatabase(TaskProcess): diff --git a/contrib/fd-plugins/bareos_tasks/mysql/README.md b/contrib/fd-plugins/bareos_tasks/mysql/README.md index 909d384e7..ec1fb9c10 100644 --- a/contrib/fd-plugins/bareos_tasks/mysql/README.md +++ b/contrib/fd-plugins/bareos_tasks/mysql/README.md @@ -1,6 +1,6 @@ # Bareos FileDaemon MySQL Plugin This plugin makes backup of any database found in a MySQL. Each databases is stored in an individual files. -For restore select the needed database file, found in */@MYSQL* in the catalog. +For restore select the needed database file, found in *@MYSQL* in the catalog. ## Prerequisites The *mysqldump* and *mysql* command must be installed and user *root* must have read-access to the databases. @@ -10,7 +10,7 @@ You need the packages *bareos-filedaemon-python-plugin* installed on your client ## Installation 1. Make sure you have met the prerequisites. -2. Install the files *BareosFdTaskClass.py*, *psql/BareosFdMySQLClass.py* and *psql/bareos-fd-mysql.py* in your Bareos plugin directory (usually */usr/lib/bareos/plugins*) +2. Make the *bareos_tasks* directory available at the path specified with *module_path* ## Configuration @@ -32,9 +32,9 @@ FileSet { compression = LZ4 signature = MD5 } - File = /etc - #... - Plugin = "python:module_path=/usr/lib/bareos/plugins:module_name=bareos-fd-mysql" + Plugin = "python:" + "module_path=/usr/lib/bareos/plugins:" + "module_name=bareos_tasks.mysql" } } } @@ -42,11 +42,14 @@ FileSet { ### Options You can append options to the plugin call as key=value pairs, separated by ':'. -Please read more about the Bareos Python Plugin Interface here: http://doc.bareos.org/master/html/bareos-manual-main-reference.html#Python-fdPlugin +Please read more about the Bareos Python Plugin Interface here: https://docs.bareos.org/TasksAndConcepts/Plugins.html#python-fd-plugin Example plugin options: ``` - Plugin = "python:module_path=/usr/lib/bareos/plugins:module_name=bareos-fd-mysql:databases=db001,db002" + Plugin = "python:" + "module_path=/usr/lib/bareos/plugins:" + "module_name=bareos_tasks.mysql:" + "databases=db001,db002" ``` #### folder @@ -68,4 +71,4 @@ Username of the system user running the *mysql* and *mysqldump* tools. Default: Comma separated list of database names to backup, if unset all databases (except 'performance_schema' and 'information_schema') are dumped. Default: unset #### exclude -Comma separated list of database names exclude from backup. Default: unset
\ No newline at end of file +Comma separated list of database names exclude from backup. Default: unset diff --git a/contrib/fd-plugins/bareos_tasks/mysql/__init__.py b/contrib/fd-plugins/bareos_tasks/mysql/__init__.py index e69de29bb..68ee1e0fe 100644 --- a/contrib/fd-plugins/bareos_tasks/mysql/__init__.py +++ b/contrib/fd-plugins/bareos_tasks/mysql/__init__.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# -*- Mode: Python; tab-width: 4 -*- +# +# Bareos FileDaemon Task plugin +# Copyright (C) 2018 Marco Lertora <marco.lertora@gmail.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +import BareosFdWrapper +from bareosfd import bRCs +from BareosFdWrapper import * +from BareosFdMySQLClass import BareosFdMySQLClass + + +def load_bareos_plugin(plugin_def): + BareosFdWrapper.bareos_fd_plugin_object = BareosFdMySQLClass(plugin_def) + return bRCs['bRC_OK'] diff --git a/contrib/fd-plugins/bareos_tasks/mysql/bareos-fd-mysql.py b/contrib/fd-plugins/bareos_tasks/mysql/bareos-fd-mysql.py deleted file mode 100644 index a493c3b37..000000000 --- a/contrib/fd-plugins/bareos_tasks/mysql/bareos-fd-mysql.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python -# -*- Mode: Python; tab-width: 4 -*- -# -# Bareos FileDaemon Task plugin -# Copyright (C) 2018 Marco Lertora <marco.lertora@gmail.com> -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. - -import BareosFdWrapper -from bareos_fd_consts import bRCs -from BareosFdWrapper import * -from BareosFdMySQLClass import BareosFdMySQLClass - - -def load_bareos_plugin(context, plugin_def): - BareosFdWrapper.bareos_fd_plugin_object = BareosFdMySQLClass(context, plugin_def) - return bRCs['bRC_OK'] diff --git a/contrib/fd-plugins/bareos_tasks/oracle/BareosFdOracleClass.py b/contrib/fd-plugins/bareos_tasks/oracle/BareosFdOracleClass.py index 9f1a9e9e3..db370e70f 100644 --- a/contrib/fd-plugins/bareos_tasks/oracle/BareosFdOracleClass.py +++ b/contrib/fd-plugins/bareos_tasks/oracle/BareosFdOracleClass.py @@ -20,7 +20,7 @@ import os import shlex -from BareosFdTaskClass import BareosFdTaskClass, TaskProcessFIFO +from bareos_tasks.BareosFdTaskClass import BareosFdTaskClass, TaskProcessFIFO class TaskDumpDatabase(TaskProcessFIFO): @@ -28,11 +28,11 @@ class TaskDumpDatabase(TaskProcessFIFO): file_extension = 'dump' def __init__(self, db_sid, db_user, db_password, ora_home, ora_exp, ora_user, ora_exp_options): - self.database = db_user + '-' + db_sid + self.database = "{}-{}".format(db_user, db_sid) self.run_as_user = ora_user self.run_environ = dict(ORACLE_SID=db_sid, ORACLE_HOME=ora_home) ora_exp = os.path.join(ora_home, 'bin/', ora_exp) - db_credential = db_user + '/' + db_password + db_credential = "{}/{}".format(db_user, db_password) self.command = [ora_exp, db_credential] + shlex.split(ora_exp_options) + ['file=' + self.fifo_path] super(TaskDumpDatabase, self).__init__() diff --git a/contrib/fd-plugins/bareos_tasks/oracle/README.md b/contrib/fd-plugins/bareos_tasks/oracle/README.md index f4037ddd8..708e38bd0 100644 --- a/contrib/fd-plugins/bareos_tasks/oracle/README.md +++ b/contrib/fd-plugins/bareos_tasks/oracle/README.md @@ -10,7 +10,7 @@ You need the packages *bareos-filedaemon-python-plugin* installed on your client ## Installation 1. Make sure you have met the prerequisites. -2. Install the files *BareosFdTaskClass.py*, *oracle/BareosFdOracleClass.py* and *oracle/bareos-fd-oracle.py* in your Bareos plugin directory (usually */usr/lib/bareos/plugins*) +2. Make the *bareos_tasks* directory available at the path specified with *module_path* ## Configuration @@ -32,9 +32,12 @@ FileSet { compression = LZ4 signature = MD5 } - File = /etc - #... - Plugin = "python:module_path=/usr/lib/bareos/plugins:module_name=bareos-fd-oracle:db_sid=DBSID:db_user=DBUSER:db_password=DBPASSWORD" + Plugin = "python:" + "module_path=/usr/lib/bareos/plugins:" + "module_name=bareos_tasks.oracle:" + "db_sid=DBSID:" + "db_user=DBUSER:" + "db_password=DBPASSWORD" } } } @@ -42,11 +45,16 @@ FileSet { ### Options You can append options to the plugin call as key=value pairs, separated by ':'. -Please read more about the Bareos Python Plugin Interface here: http://doc.bareos.org/master/html/bareos-manual-main-reference.html#Python-fdPlugin +Please read more about the Bareos Python Plugin Interface here: https://docs.bareos.org/TasksAndConcepts/Plugins.html#python-fd-plugin Example plugin options: ``` - Plugin = "python:module_path=/usr/lib/bareos/plugins:module_name=bareos-fd-oracle:db_sid=MAIN:db_user=oracle:db_password=secret" + Plugin = "python:" + "module_path=/usr/lib/bareos/plugins:" + "module_name=bareos_tasks.oracle:" + "db_sid=MAIN:" + "db_user=oracle:" + "db_password=secret" ``` #### folder @@ -71,4 +79,4 @@ Specifies the *sid* of the oracle instance to use. Required Specifies the username of the user performing the export. Required #### db_password -Specifies the password of the user performing the export. Required
\ No newline at end of file +Specifies the password of the user performing the export. Required diff --git a/contrib/fd-plugins/bareos_tasks/oracle/__init__.py b/contrib/fd-plugins/bareos_tasks/oracle/__init__.py index e69de29bb..4a2e09175 100644 --- a/contrib/fd-plugins/bareos_tasks/oracle/__init__.py +++ b/contrib/fd-plugins/bareos_tasks/oracle/__init__.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# -*- Mode: Python; tab-width: 4 -*- +# +# Bareos FileDaemon Task plugin +# Copyright (C) 2018 Marco Lertora <marco.lertora@gmail.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +import BareosFdWrapper +from bareosfd import bRCs +from BareosFdWrapper import * +from BareosFdOracleClass import BareosFdOracleClass + + +def load_bareos_plugin(plugin_def): + BareosFdWrapper.bareos_fd_plugin_object = BareosFdOracleClass(plugin_def) + return bRCs['bRC_OK'] diff --git a/contrib/fd-plugins/bareos_tasks/oracle/bareos-fd-oracle.py b/contrib/fd-plugins/bareos_tasks/oracle/bareos-fd-oracle.py deleted file mode 100644 index 39d93dd3d..000000000 --- a/contrib/fd-plugins/bareos_tasks/oracle/bareos-fd-oracle.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python -# -*- Mode: Python; tab-width: 4 -*- -# -# Bareos FileDaemon Task plugin -# Copyright (C) 2018 Marco Lertora <marco.lertora@gmail.com> -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. - -import BareosFdWrapper -from bareos_fd_consts import bRCs -from BareosFdWrapper import * -from BareosFdOracleClass import BareosFdOracleClass - - -def load_bareos_plugin(context, plugin_def): - BareosFdWrapper.bareos_fd_plugin_object = BareosFdOracleClass(context, plugin_def) - return bRCs['bRC_OK'] diff --git a/contrib/fd-plugins/bareos_tasks/pgsql/README.md b/contrib/fd-plugins/bareos_tasks/pgsql/README.md index 96f33795c..1b4a52847 100644 --- a/contrib/fd-plugins/bareos_tasks/pgsql/README.md +++ b/contrib/fd-plugins/bareos_tasks/pgsql/README.md @@ -1,6 +1,6 @@ # Bareos FileDaemon PostgreSQL Plugin This plugin makes backup of any database found in a PostgreSQL. Each databases is stored in an individual files. -For restore select the needed database file, found in */@PGSQL* in the catalog. +For restore select the needed database file, found in *@PGSQL* in the catalog. ## Prerequisites The *pg_dump* and *psql* command must be installed and user *postgres* must have read-access to the databases. @@ -10,7 +10,7 @@ You need the packages *bareos-filedaemon-python-plugin* installed on your client ## Installation 1. Make sure you have met the prerequisites. -2. Install the files *BareosFdTaskClass.py*, *psql/BareosFdPgSQLClass.py* and *psql/bareos-fd-pgsql.py* in your Bareos plugin directory (usually */usr/lib/bareos/plugins*) +2. Make the *bareos_tasks* directory available at the path specified with *module_path* ## Configuration @@ -32,9 +32,9 @@ FileSet { compression = LZ4 signature = MD5 } - File = /etc - #... - Plugin = "python:module_path=/usr/lib/bareos/plugins:module_name=bareos-fd-pgsql" + Plugin = "python:" + "module_path=/usr/lib/bareos/plugins:" + "module_name=bareos_tasks.pgsql" } } } @@ -42,11 +42,14 @@ FileSet { ### Options You can append options to the plugin call as key=value pairs, separated by ':'. -Please read more about the Bareos Python Plugin Interface here: http://doc.bareos.org/master/html/bareos-manual-main-reference.html#Python-fdPlugin +Please read more about the Bareos Python Plugin Interface here: https://docs.bareos.org/TasksAndConcepts/Plugins.html#python-fd-plugin Example plugin options: ``` - Plugin = "python:module_path=/usr/lib/bareos/plugins:module_name=bareos-fd-pgsql:databases=db001,db002" + Plugin = "python:" + "module_path=/usr/lib/bareos/plugins:" + "module_name=bareos_tasks.pgsql:" + "databases=db001,db002" ``` #### folder diff --git a/contrib/fd-plugins/bareos_tasks/pgsql/__init__.py b/contrib/fd-plugins/bareos_tasks/pgsql/__init__.py index 338ff5bfa..d43f35705 100644 --- a/contrib/fd-plugins/bareos_tasks/pgsql/__init__.py +++ b/contrib/fd-plugins/bareos_tasks/pgsql/__init__.py @@ -18,9 +18,13 @@ # along with this program. If not, see <https://www.gnu.org/licenses/>. import bareosfd -import BareosFdWrapper from BareosFdPgSQLClass import BareosFdPgSQLClass +# This module contains the wrapper functions called by the Bareos-FD, the +# functions call the corresponding methods from your plugin class +import BareosFdWrapper +from BareosFdWrapper import * + def load_bareos_plugin(plugin_def): BareosFdWrapper.bareos_fd_plugin_object = BareosFdPgSQLClass(plugin_def) diff --git a/contrib/fd-plugins/bareos_tasks/xenserver/BareosFdXenServerClass.py b/contrib/fd-plugins/bareos_tasks/xenserver/BareosFdXenServerClass.py index fd1e64869..d6bacc728 100644 --- a/contrib/fd-plugins/bareos_tasks/xenserver/BareosFdXenServerClass.py +++ b/contrib/fd-plugins/bareos_tasks/xenserver/BareosFdXenServerClass.py @@ -18,7 +18,7 @@ # along with this program. If not, see <https://www.gnu.org/licenses/>. import socket -from BareosFdTaskClass import TaskProcess, BareosFdTaskClass +from bareos_tasks.BareosFdTaskClass import TaskProcess, BareosFdTaskClass class TaskHostBackup(TaskProcess): diff --git a/contrib/fd-plugins/bareos_tasks/xenserver/README.md b/contrib/fd-plugins/bareos_tasks/xenserver/README.md index fb4dbd776..9b0f7d8e6 100644 --- a/contrib/fd-plugins/bareos_tasks/xenserver/README.md +++ b/contrib/fd-plugins/bareos_tasks/xenserver/README.md @@ -14,7 +14,7 @@ You need the packages *bareos-filedaemon-python-plugin* installed on your client ## Installation 1. Make sure you have met the prerequisites. -2. Install the files *BareosFdTaskClass.py*, *xenserver/BareosFdXenServerClass.py* and *xenserver/bareos-fd-xenserver.py* in your Bareos plugin directory (usually */usr/lib/bareos/plugins*) +2. Make the *bareos_tasks* directory available at the path specified with *module_path* ## Configuration @@ -27,7 +27,7 @@ FileDaemon { } ``` -nclude the Plugin in the fileset definition on the director +Include the Plugin in the fileset definition on the director ``` FileSet { Name = "client-data" @@ -36,9 +36,9 @@ FileSet { compression = LZO signature = MD5 } - File = /etc - #... - Plugin = "python:module_path=/usr/lib/bareos/plugins:module_name=bareos-fd-xenserver" + Plugin = "python:" + "module_path=/usr/lib/bareos/plugins:" + "module_name=bareos_tasks.xenserver" } } } @@ -46,11 +46,14 @@ FileSet { ### Options You can append options to the plugin call as key=value pairs, separated by ':'. -Please read more about the Bareos Python Plugin Interface here: http://doc.bareos.org/master/html/bareos-manual-main-reference.html#Python-fdPlugin +Please read more about the Bareos Python Plugin Interface here: https://docs.bareos.org/TasksAndConcepts/Plugins.html#python-fd-plugin Example plugin options: ``` - Plugin = "python:module_path=/usr/lib/bareos/plugins:module_name=bareos-fd-xenserver:host_backup=yes" + Plugin = "python:" + "module_path=/usr/lib/bareos/plugins:" + "module_name=bareos_tasks.xenserver:" + "host_backup=yes" ``` #### folder diff --git a/contrib/fd-plugins/bareos_tasks/xenserver/__init__.py b/contrib/fd-plugins/bareos_tasks/xenserver/__init__.py index e69de29bb..c19d901c5 100644 --- a/contrib/fd-plugins/bareos_tasks/xenserver/__init__.py +++ b/contrib/fd-plugins/bareos_tasks/xenserver/__init__.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# -*- Mode: Python; tab-width: 4 -*- +# +# Bareos FileDaemon Task plugin +# Copyright (C) 2018 Marco Lertora <marco.lertora@gmail.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +import BareosFdWrapper +from bareosfd import bRCs +from BareosFdWrapper import * +from BareosFdXenServerClass import BareosFdXenServerClass + + +def load_bareos_plugin(plugin_def): + BareosFdWrapper.bareos_fd_plugin_object = BareosFdXenServerClass(plugin_def) + return bRCs['bRC_OK'] diff --git a/contrib/fd-plugins/bareos_tasks/xenserver/bareos-fd-xenserver.py b/contrib/fd-plugins/bareos_tasks/xenserver/bareos-fd-xenserver.py deleted file mode 100644 index 8a4d95934..000000000 --- a/contrib/fd-plugins/bareos_tasks/xenserver/bareos-fd-xenserver.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python -# -*- Mode: Python; tab-width: 4 -*- -# -# Bareos FileDaemon Task plugin -# Copyright (C) 2018 Marco Lertora <marco.lertora@gmail.com> -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. - -import BareosFdWrapper -from bareos_fd_consts import bRCs -from BareosFdWrapper import * -from BareosFdXenServerClass import BareosFdXenServerClass - - -def load_bareos_plugin(context, plugin_def): - BareosFdWrapper.bareos_fd_plugin_object = BareosFdXenServerClass(context, plugin_def) - return bRCs['bRC_OK'] |