comments, renames
[sitarba.git] / sitarba
diff --git a/sitarba b/sitarba
index e57e2508500fe22a966357413cb6d398c73a9f20..b67925fd27435b8c236de566f5bfc58f175ca8c2 100755 (executable)
--- a/sitarba
+++ b/sitarba
@@ -224,6 +224,10 @@ class Config:
         e = Epoch()
         if name in self.epochs:
             raise Config.ReadError("Epoch '{0}' already defined.".format(name))
+        p = re.compile(r'^\w+$')
+        if not p.match(name):
+            raise Config.ReadError("Epoch name '{0}' does not only " + \
+                    "comprise alphanumeric characters.".format(name))
         if name in Epoch.units:
             e.unit = name
 
@@ -267,6 +271,11 @@ class Config:
 
     def _read_set(self, config, sec):
         name = sec[4:].strip()
+        p = re.compile(r'^\w+$')
+        if not p.match(name):
+            raise Config.ReadError("Set name '{0}' does not only " + \
+                    "comprise alphanumeric characters.".format(name))
+
         dirs = []
         excludes = []
 
@@ -347,7 +356,7 @@ class BackupManager:
         return [ d for d in dirs if os.path.isdir(os.path.join(basedir, d)) ]
 
 
-    def listOldBackups(self):
+    def listExistingBackups(self):
         """Returns a list of old backups."""
 
         backups = []
@@ -393,6 +402,10 @@ class BackupManager:
         fsfn = os.path.join(targetdir, fileset.name) + "." + self.conf.format
         taropts = []
 
+        # Tar is verbose is sitarba is verbose
+        if LogConf.con.level <= logging.DEBUG:
+            taropts += ["--verbose"]
+
         # Add the since date, if given
         if since != None:
             taropts += ["-N", since.strftime("%Y-%m-%d %H:%M:%S")]
@@ -405,11 +418,12 @@ class BackupManager:
         for pat in fileset.excludes:
             taropts += ["--exclude", pat]
 
+
         # Adding directories to backup
         taropts += ["-C", "/"] + [ "./" + d.lstrip("/") for d in fileset.dirs]
 
         # Launch the tar process
-        tarargs = [self.conf.tarbin] + ["-cpvaf", fsfn] + taropts
+        tarargs = [self.conf.tarbin] + ["-cpaf", fsfn] + taropts
         logfile.debug("tar call: " + " ".join(tarargs))
         tarp = subprocess.Popen( tarargs, bufsize=-1, \
                 stdout=subprocess.PIPE, stderr=subprocess.PIPE )
@@ -449,7 +463,7 @@ class BackupManager:
         then use mode for given epoch. Use given mode otherwise."""
 
         now = datetime.datetime.now()
-        oldbackups = self.listOldBackups()
+        oldbackups = self.listExistingBackups()
 
         # Get epoch of backup
         if epoch == None:
@@ -526,14 +540,16 @@ class BackupManager:
         """Prune old backup files"""
 
         allDirs = sorted(self.listAllDirs())
-        # Collect all directories not matching backup name
+        # Collect all directories that are removed
         removeDirs = [ d for d in allDirs if not Backup.isBackupDir(d) ]
 
-        # Get all directories which are kept
-        backups = self.listOldBackups()
-        keepdirs = []
+        # Get all backups
+        backups = self.listExistingBackups()
+        # Group backups by epoch and sort them by age
         byepoch = { e : list(sorted( [ b for b in backups if b.epoch == e ], \
-                key=lambda b : b.date, reverse=True)) for e in self.conf.getRealEpochsSorted() }
+                key=lambda b : b.date, reverse=True)) \
+                for e in self.conf.getRealEpochsSorted() }
+        # If we have too many backups of a specific epoch --> add them to remove list
         for e in byepoch:
             epoch = self.conf.epochs[e]
             old = byepoch[e][epoch.numkeeps:]
@@ -583,7 +599,7 @@ class BackupManager:
 def printUsage():
     """Print --help text"""
 
-    print("shbackup - a simple backup solution.")
+    print("sitarba - a simple backup solution.")
     print("")
     print("Usage:")
     print("  " + sys.argv[0] + " {options} [cmd]")
@@ -597,7 +613,7 @@ def printUsage():
     print("Options:")
     print("  -h, --help                 print this usage text")
     print("  -c, --conf FILE            use given configuration file")
-    print("                             default: /etc/shbackup.conf")
+    print("                             default: /etc/sitarba.conf")
     print("  -e, --epoch EPOCH          force to create backup for given epoch, which")
     print("                             can be 'sporadic' or one of the configured epochs")
     print("  -m, --mode MODE            override mode: full, diff, or incr")
@@ -630,7 +646,7 @@ if __name__ == "__main__":
 
     LogConf.setup()
 
-    conffn = "/etc/shbackup.conf"
+    conffn = "/etc/sitarba.conf"
     cmd = "list"
     mode = None
     epoch = None
@@ -649,7 +665,7 @@ if __name__ == "__main__":
             conffn = sys.argv[i]
 
         elif opt in ["-V", "--version"]:
-            print("shbackup " + __version__)
+            print("sitarba " + __version__)
             exit(0)
 
         elif opt in ["-v", "--verbose"]:
@@ -694,7 +710,7 @@ if __name__ == "__main__":
             man.backup(epoch, mode)
 
         if cmd == "list":
-            for b in sorted(man.listOldBackups(), key=lambda b: b.date):
+            for b in sorted(man.listExistingBackups(), key=lambda b: b.date):
                 print(b.colAlignedString())
 
         if cmd == "prune":