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

svn at pcbsd.org svn at pcbsd.org
Tue Nov 10 11:16:27 PST 2009


Author: kris
Date: 2009-11-10 11:16:27 -0800 (Tue, 10 Nov 2009)
New Revision: 4931

Added:
   pcbsd/trunk/lifePreserver/lifePreserverSettings.cpp
   pcbsd/trunk/lifePreserver/lifePreserverSettings.h
Modified:
   pcbsd/trunk/lifePreserver/lPreserve.pro
   pcbsd/trunk/lifePreserver/lifePreserverMain.cpp
   pcbsd/trunk/lifePreserver/lifePreserverMain.h
   pcbsd/trunk/lifePreserver/lifePreserverSettings.ui
   pcbsd/trunk/lifePreserver/lifePreserverWizard.cpp
   pcbsd/trunk/lifePreserver/preserver.cpp
   pcbsd/trunk/lifePreserver/preserver.h
   pcbsd/trunk/lifePreserver/scripts/backup-rsync.sh
   pcbsd/trunk/lifePreserver/scripts/functions.sh
   pcbsd/trunk/lifePreserver/scripts/start-backup.sh
Log:

Large update to life-perserver, now able to edit saved preservers, change settings, and finished up alternative 
port support, also improving shell script stuff, and getting ready to implement cleanup / restore features. 



Modified: pcbsd/trunk/lifePreserver/lPreserve.pro
===================================================================
--- pcbsd/trunk/lifePreserver/lPreserve.pro	2009-11-10 10:00:30 UTC (rev 4930)
+++ pcbsd/trunk/lifePreserver/lPreserve.pro	2009-11-10 19:16:27 UTC (rev 4931)
@@ -5,13 +5,13 @@
 
 LIBS += -L/usr/local/kde4/lib -lkdecore -lkio -lkdeui -Ikdelibs
 
-HEADERS	+= lifePreserverMain.h lifePreserverWizard.h preserver.h
+HEADERS	+= lifePreserverMain.h lifePreserverWizard.h lifePreserverSettings.h preserver.h
 
-SOURCES	+= main.cpp lifePreserverMain.cpp lifePreserverWizard.cpp preserver.cpp
+SOURCES	+= main.cpp lifePreserverMain.cpp lifePreserverWizard.cpp lifePreserverSettings.cpp preserver.cpp
 
 RESOURCES += lPreserve.qrc
 
-FORMS	= lifePreserverMain.ui lifePreserverWizard.ui
+FORMS	= lifePreserverMain.ui lifePreserverWizard.ui lifePreserverSettings.ui
 
 #DESTDIR = /usr/local/kde4/bin
 

Modified: pcbsd/trunk/lifePreserver/lifePreserverMain.cpp
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverMain.cpp	2009-11-10 10:00:30 UTC (rev 4930)
+++ pcbsd/trunk/lifePreserver/lifePreserverMain.cpp	2009-11-10 19:16:27 UTC (rev 4931)
@@ -39,6 +39,8 @@
 #include "lifePreserverMain.h"
 #include "ui_lifePreserverWizard.h"
 #include "lifePreserverWizard.h"
+#include "ui_lifePreserverSettings.h"
+#include "lifePreserverSettings.h"
 #include "preserver.h"
 #include "externals.h"
 
@@ -140,7 +142,15 @@
 // Slot to edit a preserver host
 void lifePreserver::slotPushEditPreserverClicked()
 {
+   if (treePreservers->currentColumn() == -1)
+   {
+      return;
+   }
 
+   lps = new pSettings();
+   lps->widgetInit(treePreservers->currentItem()->text(0));
+   lps->setWindowModality( Qt::WindowModal );
+   lps->show();
 }
 
 // Slot to start the creation of a new life preserver
@@ -148,6 +158,7 @@
 {
    lpw = new lifePreserverWizard();
    lpw->widgetInit();
+   lpw->setWindowModality( Qt::WindowModal );
    connect(lpw, SIGNAL( added() ), this, SLOT(loadPreservers() ) );
    lpw->show();
 

Modified: pcbsd/trunk/lifePreserver/lifePreserverMain.h
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverMain.h	2009-11-10 10:00:30 UTC (rev 4930)
+++ pcbsd/trunk/lifePreserver/lifePreserverMain.h	2009-11-10 19:16:27 UTC (rev 4931)
@@ -10,6 +10,8 @@
 #include "ui_lifePreserverMain.h"
 #include "ui_lifePreserverWizard.h"
 #include "lifePreserverWizard.h"
+#include "ui_lifePreserverSettings.h"
+#include "lifePreserverSettings.h"
 
 /* KDE */
 #include <kmenu.h>
@@ -41,6 +43,7 @@
 
 private:
    lifePreserverWizard *lpw;
+   pSettings *lps;
    QString getPreserverLastBackup(QString host);
    QString getPreserverFrequency(QString host);
    QString getPreserverStatus(QString host);

Modified: pcbsd/trunk/lifePreserver/lifePreserverSettings.ui
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverSettings.ui	2009-11-10 10:00:30 UTC (rev 4930)
+++ pcbsd/trunk/lifePreserver/lifePreserverSettings.ui	2009-11-10 19:16:27 UTC (rev 4931)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <ui version="4.0">
  <class>pSettings</class>
- <widget class="QWidget" name="pSettings">
+ <widget class="QDialog" name="pSettings">
   <property name="geometry">
    <rect>
     <x>0</x>
@@ -38,7 +38,7 @@
            </sizepolicy>
           </property>
           <property name="text">
-           <string>Number of Backups to keep</string>
+           <string> Number of backups to keep</string>
           </property>
          </widget>
         </item>

Modified: pcbsd/trunk/lifePreserver/lifePreserverWizard.cpp
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverWizard.cpp	2009-11-10 10:00:30 UTC (rev 4930)
+++ pcbsd/trunk/lifePreserver/lifePreserverWizard.cpp	2009-11-10 19:16:27 UTC (rev 4931)
@@ -168,6 +168,7 @@
    myPreserver.setPort(spinPort->value());
    myPreserver.setType("rsync");
    myPreserver.setNumBackups(7);
+   myPreserver.setFailedCleanup(true);
 
    if ( radioDaily->isChecked() )
    {

Modified: pcbsd/trunk/lifePreserver/preserver.cpp
===================================================================
--- pcbsd/trunk/lifePreserver/preserver.cpp	2009-11-10 10:00:30 UTC (rev 4930)
+++ pcbsd/trunk/lifePreserver/preserver.cpp	2009-11-10 19:16:27 UTC (rev 4931)
@@ -1,6 +1,6 @@
 /***************************************************************************
- *   Copyright (C) 2007 by Tim McCormick   *
- *   tim at pcbsd.org   *
+ *   Copyright (C) 2009 by Kris Moore   *
+ *   kris at pcbsd.org   *
  *                                                                         *
  *   Permission is hereby granted, free of charge, to any person obtaining *
  *   a copy of this software and associated documentation files (the       *
@@ -151,6 +151,11 @@
 
 }
 
+void PRESERVER::setFailedCleanup(bool enabled)
+{
+  setConfValue("cleanfailed", enabled);
+}
+
 void PRESERVER::setHost(QString userHost)
 {
   setConfValue("host", userHost);
@@ -176,6 +181,11 @@
   return getConfValue("host").toString();
 }
 
+bool PRESERVER::getFailedCleanup()
+{
+  return getConfValue("cleanfailed").toBool();
+}
+
 int PRESERVER::getNumBackups()
 {
   return getConfValue("keepbackups").toInt();
@@ -207,7 +217,38 @@
   return result;
 }
 
-// Function which returns the cron status of this backup
+
+// Function which returns the cron time for internal use
+QString PRESERVER::getCronSettings()
+{
+  QString result = "disabled";
+  QString hour, day;
+
+  QFile cronFile( "/etc/crontab" );
+  if ( cronFile.open( QIODevice::ReadOnly ) )
+  {
+    QTextStream stream( &cronFile );
+    QString line;
+    while ( !stream.atEnd() ) {
+      line = stream.readLine(); // line of text excluding '\n'
+      // Check if we have a match for this backup
+      if ( line.indexOf(connectHost) != -1  ) {
+         // Now read the line and return details about the backup time
+         QString tmp = line.simplified();
+         hour = tmp.section(" ", 1,1);
+         day = tmp.section(" ", 4,4);
+         result = day + ":" + hour;
+         return result;
+      }
+    }
+    cronFile.close();
+  }
+
+  
+  return result;
+}
+
+// Function which returns the cron status of this backup for end user display
 QString PRESERVER::getFrequency()
 {
   QString schedule = "Unknown";

Modified: pcbsd/trunk/lifePreserver/preserver.h
===================================================================
--- pcbsd/trunk/lifePreserver/preserver.h	2009-11-10 10:00:30 UTC (rev 4930)
+++ pcbsd/trunk/lifePreserver/preserver.h	2009-11-10 19:16:27 UTC (rev 4931)
@@ -1,6 +1,6 @@
 /***************************************************************************
- *   Copyright (C) 2007 by Tim McCormick   *
- *   tim at pcbsd.org   *
+ *   Copyright (C) 2009 by Kris Moore   *
+ *   kris at pcbsd.org   *
  *                                                                         *
  *   Permission is hereby granted, free of charge, to any person obtaining *
  *   a copy of this software and associated documentation files (the       *
@@ -42,7 +42,9 @@
     virtual int getNumBackups();
     virtual QString getLastBackup();
     virtual QString getFrequency();
+    virtual QString getCronSettings();
     virtual int getPID();
+    virtual bool getFailedCleanup();
     
     //Setters
     virtual void setHost(QString userhost);
@@ -51,14 +53,15 @@
     virtual void setType(QString type);
     virtual void setCron(QString hour);
     virtual void setCron(QString hour, QString day);
+    virtual void setFailedCleanup(bool enabled);
 
     virtual void remove();
+    virtual void removeCron();
     virtual void startBackup();
     virtual void stopBackup();
 
 private:
     void setConfValue(QString key, QVariant value);
-    virtual void removeCron();
     QVariant getConfValue(QString key);
     QString connectHost;
 

Modified: pcbsd/trunk/lifePreserver/scripts/backup-rsync.sh
===================================================================
--- pcbsd/trunk/lifePreserver/scripts/backup-rsync.sh	2009-11-10 10:00:30 UTC (rev 4930)
+++ pcbsd/trunk/lifePreserver/scripts/backup-rsync.sh	2009-11-10 19:16:27 UTC (rev 4931)
@@ -18,6 +18,7 @@
 PIDFILE="${HOSTDIR}/preserver.pid"
 RESULTFILE="${HOSTDIR}/last-result"
 STARTDATE=`date "+%H:%M %m-%d-%y"`
+SETTINGS="${HOSTDIR}/settings.conf"
 
 # Source our functions
 . ${PROGDIR}/scripts/functions.sh
@@ -29,6 +30,21 @@
   exit 1
 fi
 
+# Start by reading in some settings from the config
+get_setting ${SETTINGS} "keepbackups"
+KEEPNUM="${VAL}"
+get_setting ${SETTINGS} "port"
+PORT="${VAL}"
+get_setting ${SETTINGS} "cleanfailed"
+CLEANFAILED="${VAL}"
+
+# Make sure we have a sane port number
+if [ -z "${PORT}" ]
+then
+  PORT="22"
+fi
+
+
 # Make sure this host has its logs dir
 if [ ! -d "${HOSTDIR}/logs" ]
 then
@@ -56,10 +72,10 @@
   --perms --chmod=o-t \
   --log-file=${BACKLOG} \
   --exclude-from ${EXCLUDELIST} \
-  -e ssh \
+  -e "ssh -p ${PORT}" \
   --link-dest=../current \
   / ${SSHHOST}:${BACKDIR}/incomplete_back-$DATE \
-  && ssh ${SSHHOST} \
+  && ssh -p ${PORT} ${SSHHOST} \
   "mv ${BACKDIR}/incomplete_back-$DATE ${BACKDIR}/back-$DATE \
   && rm -f ${BACKDIR}/current \
   && ln -s back-${DATE} ${BACKDIR}/current"
@@ -69,7 +85,7 @@
   bzip2 ${BACKLOG}
   # Success!
   # Copy the logfile to the backup dir
-  sftp ${SSHHOST} << EOF
+  sftp -oPORT=${PORT} ${SSHHOST} << EOF
 cd ${BACKDIR}/current
 put ${BACKLOG}.bz2 backup.log.bz2
 quit

Modified: pcbsd/trunk/lifePreserver/scripts/functions.sh
===================================================================
--- pcbsd/trunk/lifePreserver/scripts/functions.sh	2009-11-10 10:00:30 UTC (rev 4930)
+++ pcbsd/trunk/lifePreserver/scripts/functions.sh	2009-11-10 19:16:27 UTC (rev 4931)
@@ -11,3 +11,21 @@
     return 0
   fi
 };
+
+get_setting()
+{
+  SETTINGS="$1"
+  KEY="$2"
+  VAL=""
+
+  if [ -e "${SETTINGS}" ]
+  then
+    grep "^${KEY}: " ${SETTINGS} >/dev/null 2>/dev/null
+    if [ "$?" = "0" ]
+    then
+      VAL=`grep "^${KEY}: " ${SETTINGS} | sed "s|${KEY}: ||g"` 
+    fi
+  fi
+
+  return VAL
+};

Modified: pcbsd/trunk/lifePreserver/scripts/start-backup.sh
===================================================================
--- pcbsd/trunk/lifePreserver/scripts/start-backup.sh	2009-11-10 10:00:30 UTC (rev 4930)
+++ pcbsd/trunk/lifePreserver/scripts/start-backup.sh	2009-11-10 19:16:27 UTC (rev 4931)
@@ -23,11 +23,13 @@
   exit 1
 fi
 
-cat ${SETTINGS} | grep "type: rsync" >/dev/null 2>/dev/null
-if [ "$?" = "0" ]
+get_setting ${SETTINGS} "type"
+TYPE="${VAL}"
+if [ "$TYPE" = "rsync" ]
 then
   ${PROGDIR}/scripts/backup-rsync.sh ${PRESERVER}
 else
-  ${PROGDIR}/scripts/backup-tar.sh ${PRESERVER}
+  echo "ERROR: Invalid type: specified"
+  exit 1
 fi
 



More information about the Commits mailing list