[PC-BSD Commits] r4892 - in pcbsd/trunk/lifePreserver: . scripts

svn at pcbsd.org svn at pcbsd.org
Thu Nov 5 12:23:30 PST 2009


Author: kris
Date: 2009-11-05 12:23:30 -0800 (Thu, 05 Nov 2009)
New Revision: 4892

Modified:
   pcbsd/trunk/lifePreserver/externals.h
   pcbsd/trunk/lifePreserver/lifePreserverMain.cpp
   pcbsd/trunk/lifePreserver/lifePreserverMain.h
   pcbsd/trunk/lifePreserver/lifePreserverWizard.cpp
   pcbsd/trunk/lifePreserver/scripts/start-backup.sh
Log:

Improved life-preservers backup ability, don't use qSettings to store, instead create
conf files / directories, which will contain all the preserver goodies in time. 

Also improved the actual backup script to create logs in the correct place and check if we
are given a valid preserver



Modified: pcbsd/trunk/lifePreserver/externals.h
===================================================================
--- pcbsd/trunk/lifePreserver/externals.h	2009-11-05 18:38:43 UTC (rev 4891)
+++ pcbsd/trunk/lifePreserver/externals.h	2009-11-05 20:23:30 UTC (rev 4892)
@@ -1 +1,2 @@
 #define LIFEPRESERVERPATH QString("/usr/PCBSD/lifePreserver")
+#define LIFEPRESERVERSDIR LIFEPRESERVERPATH + QString("/preservers")

Modified: pcbsd/trunk/lifePreserver/lifePreserverMain.cpp
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverMain.cpp	2009-11-05 18:38:43 UTC (rev 4891)
+++ pcbsd/trunk/lifePreserver/lifePreserverMain.cpp	2009-11-05 20:23:30 UTC (rev 4892)
@@ -27,6 +27,9 @@
 #include <QTextStream>
 #include <QSettings>
 #include <QDateTime>
+#include <QDir>
+#include <QFile>
+#include <QDebug>
 
 #include <kmenu.h>
 
@@ -35,6 +38,7 @@
 #include "lifePreserverMain.h"
 #include "ui_lifePreserverWizard.h"
 #include "lifePreserverWizard.h"
+#include "externals.h"
 
 /* KDE */
 
@@ -71,32 +75,9 @@
    }
 
    QString removeHost = treePreservers->currentItem()->text(0);
-   QSettings settings("PCBSD");
-   QString savedPreservers[500];
-   int numExisting = 0;
-   int size = settings.beginReadArray("/lifePreserver/savedPreservers");
-   int j = 0;
-   for (int i = 0; i < size; ++i)
-   {
-     settings.setArrayIndex(i);
-     if ( settings.value("connectString").toString() != removeHost) {
-       savedPreservers[j] = settings.value("connectString").toString();
-       j++;
-       numExisting = j;
-     }
-   }
-   settings.endArray();
+   QString cmd = "rm -rf '" + LIFEPRESERVERSDIR + "/" + removeHost + "'";
+   system(cmd.toLatin1());
 
-
-   settings.beginWriteArray("/lifePreserver/savedPreservers");
-   for ( int i = 0; i < numExisting; ++i)
-   {
-     settings.setArrayIndex(i);
-     settings.setValue("connectString", savedPreservers[i] );
-   }
-   settings.endArray();
-   settings.sync();
-
    // Reload our list
    loadPreservers();
 }
@@ -123,6 +104,30 @@
    close();
 }
 
+void lifePreserver::loadPreserverFromConf(QString confFilePath)
+{
+  QFile confFile(confFilePath);
+  if ( confFile.open( QIODevice::ReadOnly ) ) 
+  {
+     QTextStream stream( &confFile );
+     QString line;
+     while ( !stream.atEnd() ) {
+       line = stream.readLine(); // line of text excluding '\n'
+       // Check if we are on a profile line
+       if ( line.indexOf("host:") == 0  ) {
+         QString preserverHost = line.replace("host: ", "");
+         qDebug() << "Found Preserver: " << confFile.fileName();
+         QStringList itemTexts;
+         itemTexts << preserverHost << getPreserverLastBackup(preserverHost) << getPreserverFrequency(preserverHost)  << getPreserverStatus(preserverHost);
+         QTreeWidgetItem *newitem = new QTreeWidgetItem(treePreservers, itemTexts);
+         treePreservers->setCurrentItem(newitem);
+         slotCurrentTreePreserverChanged(newitem);
+        }
+     }
+  }
+
+}
+
 void lifePreserver::loadPreservers()
 {
    // Make sure we disconnect our notifier before clearing the list
@@ -133,22 +138,29 @@
    pushRemovePreserver->setEnabled(false);
    pushPreserverStart->setEnabled(false);
 
-   QString tmp;
-   QSettings settings("PCBSD");
-   int size = settings.beginReadArray("/lifePreserver/savedPreservers");
-   for (int i = 0; i < size; ++i)
+   QDir confdir;
+   confdir.setPath(LIFEPRESERVERSDIR);
+   // Make sure the conf path exists
+   if ( ! confdir.exists() )
    {
-     settings.setArrayIndex(i);
-     QStringList itemTexts;
-     tmp = settings.value("connectString").toString();
-     itemTexts << tmp << getPreserverLastBackup(tmp) << getPreserverFrequency(tmp)  << getPreserverStatus(tmp);
-     QTreeWidgetItem *newitem = new QTreeWidgetItem(treePreservers, itemTexts);
-     //treePreservers->addTopLevelItem(newitem);
-     treePreservers->setCurrentItem(newitem);
-     slotCurrentTreePreserverChanged(newitem);
+      confdir.mkpath(confdir.path());
    }
-   settings.endArray();
 
+   // Now read in all the directories and look for preservers
+   confdir.setFilter(QDir::AllDirs | QDir::NoSymLinks | QDir::NoDotAndDotDot );
+
+   QStringList listPreservers = confdir.entryList();
+   for (int i = 0; i < listPreservers.size(); ++i) {
+       QString preserverDir = listPreservers.at(i); 
+       QFile confFile(confdir.path() + "/" + preserverDir + "/settings.conf");
+       if ( confFile.exists() )
+       {
+         // Load this preserver from its conf
+         loadPreserverFromConf(confFile.fileName());
+       }
+   }
+
+
    // Connect our slot to determine when the selected item has changed
    connect(treePreservers, SIGNAL( currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem *) ), this, SLOT(slotCurrentTreePreserverChanged(QTreeWidgetItem *) ) );
 

Modified: pcbsd/trunk/lifePreserver/lifePreserverMain.h
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverMain.h	2009-11-05 18:38:43 UTC (rev 4891)
+++ pcbsd/trunk/lifePreserver/lifePreserverMain.h	2009-11-05 20:23:30 UTC (rev 4892)
@@ -42,6 +42,7 @@
    QString getPreserverLastBackup(QString host);
    QString getPreserverFrequency(QString host);
    QString getPreserverStatus(QString host);
+   void loadPreserverFromConf(QString confFilePath);
 
 signals:
 

Modified: pcbsd/trunk/lifePreserver/lifePreserverWizard.cpp
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverWizard.cpp	2009-11-05 18:38:43 UTC (rev 4891)
+++ pcbsd/trunk/lifePreserver/lifePreserverWizard.cpp	2009-11-05 20:23:30 UTC (rev 4892)
@@ -157,42 +157,36 @@
 void lifePreserverWizard::savePreserver()
 {
    QString connectString = lineUserName->text() + "@" + lineHostName->text();
-   QSettings settings("PCBSD");
-   QString savedPreservers[500];
-   int numExisting = 0;
-   int size = settings.beginReadArray("/lifePreserver/savedPreservers");
-   for (int i = 0; i < size; ++i)
+
+   // Create our new Preserver Directory
+   QDir newPreserverDir;
+   newPreserverDir.setPath(LIFEPRESERVERSDIR + "/" + connectString);
+   if ( ! newPreserverDir.exists() )
    {
-     settings.setArrayIndex(i);
-     savedPreservers[i] = settings.value("connectString").toString();
-     numExisting = i;
+      newPreserverDir.mkpath(newPreserverDir.path());
    }
-   settings.endArray();
 
-   settings.beginWriteArray("/lifePreserver/savedPreservers");
-   for ( int i = 0; i < numExisting; ++i)
-   {
-     settings.setArrayIndex(i);
-     settings.setValue("connectString", savedPreservers[i] );
-     numExisting = i;
+   // Save the config
+   QFile fileout( newPreserverDir.path() + "/settings.conf" );
+   if ( fileout.open( QIODevice::WriteOnly ) ) {
+       QTextStream streamout( &fileout );
+                   streamout << "host: " + connectString << "\n";
+                   streamout << "port: 22";
+       fileout.close();
    }
-   settings.setArrayIndex(numExisting + 1);
-   settings.setValue("connectString", connectString );
-   settings.endArray();
 
 }
 
 bool lifePreserverWizard::doesPreserverExist()
-{
-   QString tmp;
-   QString searchingName = lineUserName->text() + "@" + lineHostName->text();
-   QSettings settings("PCBSD");
-   int size = settings.beginReadArray("/lifePreserver/savedPreservers");
-   for (int i = 0; i < size; ++i)
+{  
+   QString connectString = lineUserName->text() + "@" + lineHostName->text();
+
+   // Create our new Preserver Directory
+   QDir findPreserverDir;
+   findPreserverDir.setPath(LIFEPRESERVERSDIR + "/" + connectString);
+   if ( findPreserverDir.exists() )
    {
-     settings.setArrayIndex(i);
-     if ( settings.value("connectString").toString() == searchingName ) 
-       return true;
+     return true;
    }
 
    return false;

Modified: pcbsd/trunk/lifePreserver/scripts/start-backup.sh
===================================================================
--- pcbsd/trunk/lifePreserver/scripts/start-backup.sh	2009-11-05 18:38:43 UTC (rev 4891)
+++ pcbsd/trunk/lifePreserver/scripts/start-backup.sh	2009-11-05 20:23:30 UTC (rev 4892)
@@ -10,12 +10,25 @@
 fi
 
 DATE=`date "+%Y-%m-%dT%H_%M_%S"`
+PROGDIR="/PCBSD/lifePreserver"
+HOSTDIR="${PROGDIR}/preservers/${SSHHOST}"
 BACKDIR="life-preserver"
-BACKLOG="/PCBSD/lifePreserver/logs/${SSHHOST}${DATE}.log"
+BACKLOG="${HOSTDIR}/logs/${SSHHOST}${DATE}.log"
 EXCLUDELIST="/PCBSD/lifePreserver/conf/rsync-excludes"
 
-mkdir /PCBSD/lifePreserver/logs >/dev/null 2>/dev/null
+# Make sure we've been given a valid life preserver
+if [ ! -d "${HOSTDIR}" ]
+then
+  echo "ERROR: Invalid preserver: ${SSHHOST}"
+  exit 1
+fi
 
+# Make sure this host has its logs dir
+if [ -d "${HOSTDIR}/logs" ]
+then
+  mkdir ${HOSTDIR}/logs
+fi
+
 # Make sure we have the BACKDIR created
 ssh ${SSHHOST} "mkdir -p ${BACKDIR}"
 



More information about the Commits mailing list