wamdam / backy2

backy2: Deduplicating block based backup software for ceph/rbd, image files and devices
http://backy2.com/
Other
195 stars 39 forks source link

Add per job config file #8

Closed gschoenberger closed 7 years ago

gschoenberger commented 7 years ago

I am trying to add a new option to the arg parser:

+    parser.add_argument(
+        '-c', '--config', default=None, help='Use a backup specific config file', type=str)

     subparsers = parser.add_subparsers()

@@ -544,8 +546,10 @@ def main():
         #console_level = logging.INFO
     else:
         console_level = logging.INFO
-
-    Config = partial(_Config, conf_name='backy')
+    if args.config is not None and args.config != '':
+        Config = partial(_Config, conf_name='backy' + '_' + args.config)
+    else:
+        Config = partial(_Config, conf_name='backy')

But I am facing the followting exception:

 ERROR: Unexpected exception
  ERROR: backup() got an unexpected keyword argument 'config'
Traceback (most recent call last):
 File "/usr/lib/python3/dist-packages/backy2/scripts/backy.py", line 575, in main
   func(**func_args)
TypeError: backup() got an unexpected keyword argument 'config'
   INFO: Backy failed.

Unfortunately I do not know were to add the new option, so that the backup method accepts it. THX, Georg

gschoenberger commented 7 years ago

OK, maybe deleting it before calling the method is sufficient?

@@ -559,6 +563,7 @@ def main():

     # Pass over to function
     func_args = dict(args._get_kwargs())
+    del func_args['config']
wamdam commented 7 years ago

Will implement for sponsoring 2h.

gschoenberger commented 7 years ago

The following patch works as expected. Be sure to define it's own resources for each backup job!

diff --git a/scripts/backy.py b/scripts/backy.py
index 271ee49..7a19f5c 100644
--- a/scripts/backy.py
+++ b/scripts/backy.py
@@ -368,6 +368,8 @@ def main():
         '-m', '--machine-output', action='store_true', default=False)
     parser.add_argument(
         '-V', '--version', action='store_true', help='Show version')
+    parser.add_argument(
+        '-c', '--config', default=None, help='Use a backup specific config file', type=str)

     subparsers = parser.add_subparsers()

@@ -544,8 +546,10 @@ def main():
         #console_level = logging.INFO
     else:
         console_level = logging.INFO
-
-    Config = partial(_Config, conf_name='backy')
+    if args.config is not None and args.config != '':
+        Config = partial(_Config, conf_name='backy' + '_' + args.config)
+    else:
+        Config = partial(_Config, conf_name='backy')
     config = Config(section='DEFAULTS')

     # logging ERROR only when machine output is selected
@@ -559,6 +563,7 @@ def main():

     # Pass over to function
     func_args = dict(args._get_kwargs())
+    del func_args['config']
     del func_args['func']
     del func_args['verbose']
     del func_args['version']

You are then able to call: # backy2 -c my_test_vm.cfg initdb if: /etc/backy_my_test_vm.cfg exists.

wamdam commented 7 years ago

Nice! If you could create a pull request including documentation changes, that'd be awesome and I could test it. The documentation should also warn of implications when the same logs, locks, process_name or database/datastore are used. Also, I'd not use the jargon of your specific usecase as "Use a backup specific config file". I'd rather not use a help method and call the long argument "--config-file".

gschoenberger commented 7 years ago

Pull request created