]> git.frykholm.com Git - butterbackup.git/commitdiff
patch from cyberdo, take host argument for single shot run
authorroot <root@backup.codemill.se>
Mon, 23 May 2016 17:46:14 +0000 (19:46 +0200)
committerroot <root@backup.codemill.se>
Mon, 23 May 2016 17:46:14 +0000 (19:46 +0200)
butterbackup.py

index 210f8498c64b35f619f793257f32205bcc2e6796..99cf3c70ace4e298e815f88abd558f91a86ae997 100755 (executable)
@@ -71,16 +71,22 @@ class BackupRunner():
             print("No config found", self.config_dir)
             sys-exit(-1)
 
-    def run(self):
-        self.hosts = os.listdir(self.config_dir)
+    def run(self, hostlist=None):
+        self.hosts = hostlist or os.listdir(self.config_dir)
 
         for host in self.hosts:
             if host == 'default.cfg':
                 continue
             try:
+                configfile = os.path.join(self.config_dir, host)
+
+                if not os.path.exists(configfile):
+                    # Trigger logging in the except clause
+                    raise BaseException()
+
                 config = configparser.ConfigParser(strict=False)
                 config.read_file(open(os.path.join(self.config_dir, 'default.cfg'),'r'))
-                config.read(os.path.join(self.config_dir, host))
+                config.read(configfile)
             except BaseException as ex:
                 print("Config error for %s. Skipping host."%host)
                 continue
@@ -93,5 +99,9 @@ if __name__ == "__main__":
         print("You need to be root. Otherwise all permissions will be lost.")
         sys.exit(-1)
     br = BackupRunner("/etc/butterbackup")
-    br.run()
+
+    hostlist = sys.argv[1:]
+    br.run(hostlist=hostlist)
+
     sys.exit(0)
+