Răsfoiți Sursa

config extended as "environment" with all (more) data about vault

Wolfgang Ortmann 9 ani în urmă
părinte
comite
e12b58971c
3 a modificat fișierele cu 49 adăugiri și 5 ștergeri
  1. 12 0
      src/KindConfig.h
  2. 3 0
      src/Makefile
  3. 34 5
      src/kind.ag

+ 12 - 0
src/KindConfig.h

@@ -21,6 +21,18 @@ public:
     settings[key].push_back(value);
   }
 
+  void setBool(const std::string& key, bool value)
+  {
+    settings[key].resize(1);
+    settings[key][0] = value ? "true" : "false";
+  }
+
+  void setString(const std::string& key, const std::string& value)
+  {
+    settings[key].resize(1);
+    settings[key][0] = value;
+  }
+
   bool hasKey(std::string key) const;
 
   std::string getString(std::string key) const;

+ 3 - 0
src/Makefile

@@ -37,6 +37,9 @@ kind: $(OBJECTS)
 stot:	stot.o stringtools.o Lexer.o
 	$(CXX) $(LOPT) $(LIBRARY) -o stot stot.o stringtools.o Lexer.o $(LIBS)	
 
+sshtest: sshtest.o filetools.o
+	$(CXX) $(LOPT) $(LIBRARY) -o sshtest sshtest.o filetools.o $(LIBS)	
+
 static: kind
 	$(CXX) $(LOPT) $(LIBRARY) -static -o kind_static $(OBJECTS) $(LIBS)
 	strip kind_static

+ 34 - 5
src/kind.ag

@@ -159,11 +159,40 @@ string findVault(const string& v)
 
 void readVaultConfig(const string& vault, KindConfig& conf)
 {
-  string vaultpath = findVault(vault);
-  const string& vaultConfigName = vaultpath + '/' + conf.getString("vaultConfigName");
+  string vaultPath = findVault(vault);
+  const string& vaultConfigName = vaultPath + '/' + conf.getString("vaultConfigName");
   verbosePrint("reading vault config:");
   verbosePrint("  " + vaultConfigName);
   conf.addFile(vaultConfigName);
+
+  // postprocessing
+
+  conf.setString("vaultPath", vaultPath);
+  bool shellMode = true;
+
+  string host;
+  if (conf.hasKey("host"))
+    host = conf.getString("host");
+
+  string server;
+  if (conf.hasKey("server"))
+    {
+      server = conf.getString("server");
+      shellMode = false;
+    }
+
+  if (!host.empty() && !server.empty())
+    throw Exception("backupVault", "Cannot have host and server");
+
+  if (host.empty() && server.empty())
+    throw Exception("backupVault", "No host or server specified");
+
+  conf.setBool("shellMode", shellMode);
+
+  if (conf.hasKey("setRule"))
+    conf.setBool("useBackupSet", true);
+  else
+    conf.setBool("useBackupSet", false);
 }
 
 string getImageName(const KindConfig& conf,
@@ -289,7 +318,7 @@ void doBackup(const string& vault,
 
   string rsyncCmd = "rsync -vrltH --delete --stats -D --numeric-ids ";
   if (!conf.getBool("ignorePermission"))
-    rsyncCmd += "-pgo";
+    rsyncCmd += "-pgo ";
   vector<string> rso = conf.getStrings("rsyncOption");
   for (const string& opt : rso)
     rsyncCmd += opt + " ";
@@ -362,8 +391,8 @@ void doBackup(const string& vault,
       verbosePrint("syncing (" + rsyncCmd + ")");
       int rc;
       backupResult = localExec(rsyncCmd, rc, debug, imageFullName + "/rsync-log");
-      if (rc == 0 ||
-          rc == 24 || // "no error" or "vanished source files" (ignored)
+      if (rc == 0 ||  // "no error"
+          rc == 24 || // "vanished source files" (ignored)
           rc == 6144) // workaround for wrong exit code ??!!
         {
           unlink(errorfile.c_str());