]> git.frykholm.com Git - butterbackup.git/blobdiff - butterbackup.py
Applied patch from tuttle@somsants.net.
[butterbackup.git] / butterbackup.py
index a1086b993c0db1a4df80fb23d2e8f3449ce8f99f..110077c1065fe23c9726306a3fd84f5e74107425 100755 (executable)
@@ -29,10 +29,15 @@ class Host():
                 return() 
             
         command = ("rsync -a --acls --xattrs --whole-file --numeric-ids --delete --delete-excluded --human-readable --inplace ")
-        excludes = " --exclude " + " --exclude ".join(self.config.get("host", "exclude").split(',')) #FIXME
+        if self.config.has_option("host", "include"):
+            includes = " --include " + " --include ".join(self.config.get("host", "include").split(',')) #FIXME
+            command = command + includes
+        if self.config.has_option("host", "exclude"):
+            excludes = " --exclude " + " --exclude ".join(self.config.get("host", "exclude").split(',')) #FIXME
+            command = command + excludes
         try:
-            print(command + excludes + " root@%s:/ "%(self.name) + self.subvol_dir)
-            check_call(shlex.split(command + excludes + " root@%s:/ "%(self.name) + self.subvol_dir))
+            print(command + " root@%s:/ "%(self.name) + self.subvol_dir)
+            check_call(shlex.split(command + " root@%s:/ "%(self.name) + self.subvol_dir))
         except CalledProcessError as ex:
             if ex.returncode in (24,):
                 pass
@@ -73,16 +78,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
@@ -95,5 +106,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)
+