Alpha Framework alpha--tasks
[ class tree: alpha--tasks ] [ index: alpha--tasks ] [ all elements ]

Source for file BackupTask.inc

Documentation is available at BackupTask.inc

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/util/AlphaTaskInterface.inc';
  4. require_once $config->get('sysRoot').'alpha/util/AlphaBackupUtils.inc';
  5. require_once $config->get('sysRoot').'alpha/util/AlphaFileUtils.inc';
  6.  
  7. /**
  8.  * A cron task for backup up the system database and select folders
  9.  * 
  10.  * @package alpha::tasks
  11.  * @since 1.1
  12.  * @author John Collins <dev@alphaframework.org>
  13.  * @version $Id: BackupTask.inc 1453 2011-12-04 15:12:54Z johnc $
  14.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  15.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  16.  *  All rights reserved.
  17.  * 
  18.  *  <pre>
  19.  *  Redistribution and use in source and binary forms, with or
  20.  *  without modification, are permitted provided that the
  21.  *  following conditions are met:
  22.  * 
  23.  *  * Redistributions of source code must retain the above
  24.  *    copyright notice, this list of conditions and the
  25.  *    following disclaimer.
  26.  *  * Redistributions in binary form must reproduce the above
  27.  *    copyright notice, this list of conditions and the
  28.  *    following disclaimer in the documentation and/or other
  29.  *    materials provided with the distribution.
  30.  *  * Neither the name of the Alpha Framework nor the names
  31.  *    of its contributors may be used to endorse or promote
  32.  *    products derived from this software without specific
  33.  *    prior written permission.
  34.  *   
  35.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  36.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  37.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  38.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  40.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  42.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  43.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  44.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  45.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  46.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  47.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  48.  *  </pre>
  49.  *  
  50.  */
  51. class BackupTask implements AlphaTaskInterface {
  52.     /**
  53.      * Trace logger
  54.      * 
  55.      * @var Logger 
  56.      */
  57.     private static $logger null;
  58.     
  59.     /**
  60.      * (non-PHPdoc)
  61.      * @see alpha/util/AlphaTaskInterface#doTask()
  62.      */
  63.     public function doTask({
  64.         global $config;
  65.         
  66.         self::$logger new Logger('BackupTask');
  67.         self::$logger->setLogFile($config->get('sysRoot').'logs/tasks.log');
  68.         
  69.         if(!file_exists($config->get('sysBackupDir')))
  70.             mkdir($config->get('sysBackupDir'));
  71.             
  72.         $targetDir $config->get('sysBackupDir').date("d-m-Y").'/';
  73.             
  74.         if(file_exists($targetDir))
  75.             AlphaFileUtils::deleteDirectoryContents($targetDir);
  76.         
  77.         if(!file_exists($targetDir))
  78.             mkdir($targetDir);
  79.             
  80.         $back new AlphaBackUpUtils();
  81.         $back->backUpAttachmentsAndLogs($targetDir);
  82.         $back->backUpDatabase($targetDir);
  83.         
  84.         $additionalDirectories explode(','$config->get('sysBackupIncludeDirs'));
  85.         
  86.         if(count($additionalDirectories0{
  87.             foreach($additionalDirectories as $additionalDirectory)
  88.                 AlphaFileUtils::copy($additionalDirectory$targetDir.basename($additionalDirectory));
  89.         }
  90.         
  91.         if($config->get('sysBackupCompress')) {
  92.             AlphaFileUtils::zip($targetDir$targetDir.date("d-m-Y").'.zip');
  93.             
  94.             // we can safely remove the uncompressed files now to save space...
  95.             AlphaFileUtils::deleteDirectoryContents($targetDir.'logs');
  96.             rmdir($targetDir.'logs');
  97.             
  98.             AlphaFileUtils::deleteDirectoryContents($targetDir.'attachments');
  99.             rmdir($targetDir.'attachments');
  100.             
  101.             unlink($targetDir.$config->get('sysDB').'_'.date("d-m-Y").'.sql');
  102.             
  103.             if(count($additionalDirectories0{
  104.                 foreach($additionalDirectories as $additionalDirectory{
  105.                     AlphaFileUtils::deleteDirectoryContents($targetDir.basename($additionalDirectory));
  106.                     rmdir($targetDir.basename($additionalDirectory));
  107.                 }
  108.             }
  109.         }
  110.     }
  111.     
  112.     /**
  113.      * (non-PHPdoc)
  114.      * @see alpha/util/AlphaTaskInterface#getMaxRunTime()
  115.      */
  116.     public function getMaxRunTime({
  117.         return 180;
  118.     }
  119. }
  120.  
  121. ?>

Documentation generated on Tue, 13 Dec 2011 20:26:29 +0000 by phpDocumentor 1.4.3