Automatic backup

I don't know if this has been requested before, but it would be nice to have an backup feature like in WP. With my own site I put the ZP tables in the same databasa as WP. This way the WP backup utility backs up all my WP and ZP tables, once a day, and emails it to my gmail address. I will never forget to make a backup :).

A friend of mine is now using ZP as a blog. Several times I ask him if he made a backup recently, but most of the time he just forgets. Could the backup feature be made like the one in WP?

Comments

  • acrylian Administrator, Developer
    We have a database backup feature on the admin overview page since quite some versions now...you have to do it manually though.
  • The backup could be made automatic, but then when should it be done? Could be quite a burden if it is done on each and every time you save something.
  • The backup/restore script is kept as a utility, so wouldn't it be possible to simple run the script standalone via cron to achieve the same results? Seems to me that this would be the best solution.
  • acrylian Administrator, Developer
    I had the same idea, although I am not used to cron jobs at all. If you could make up some code for that this would probably a good idea. We could add it to the extensions section then.
  • in this case it should only be possible to start this script header(Location:http://www.domain.com/zp-core/utilities/backup_restore.php?backup=true&compress=0) without have to login. a cronjob can also only execute php scripts.
  • You will have to find some way for the chron job to log in. In addition, with the 1.3.1 release you will have to deal with the Cross Site Request Forgery protection. I do not know how that will work out with Chron jobs. It requires a consistend session between the request and the post processing.
  • I'm not good with PHP, but perhaps the plugin that handles backups from within WordPress could be a good example? It's this plugin: http://austinmatzko.com/wordpress-plugins/wp-db-backup/
  • Well, this Wordpress backup is not automated. So it is really no different from what we already offer.
  • From within WP this plugin can be set to 'daily' with the option to email the backup to a specified mail address. I think/thought that it was done through this plugin, but there also is this filed called cron.php in the wp-includes directory. It was just an idea :).
  • I'll look at that cron.php file and see if we can adapt it.
  • In tonight's build there is now an automatic backup plugin. It should also be possible to use a CRON job to run backup automatically, however that is not tested.

    Anyone wishing to implement a CRON automatic backup would be a big help for us. The approach is to create a PHP script for CRON to run.

    Here is the code (untested). It assumes that the script is in a folder named `CRON` which is in the root of the Zenphoto installation. (The actual folder name is not important.)

    `
    <?php
    define('OFFSET_PATH',1);
    define('KEEP',5); // the number of backups to maintain
    require_once(dirname(dirname(__FILE__)).'/zp-core/functions.php');
    $curdir = getcwd();
    chdir(SERVERPATH . "/" . BACKUPFOLDER);
    $filelist = safe_glob('*'.'.zdb');
    $list = array();
    foreach($filelist as $file) {
    $list[$file] = filemtime($file);
    }
    chdir($curdir);
    asort($list);
    $list = array_flip($list);
    while (count($list) >= KEEP) {
    $file = array_shift($list);
    unlink(SERVERPATH . "/" . BACKUPFOLDER.'/'.$file);
    }
    cron_starter( SERVERPATH.'/'.ZENFOLDER.'/'.UTILITIES_FOLDER.'/backup_restore.php',
    array('backup'=>1, 'compress'=>sprintf('%u',getOption('backup_compression')),'XSRFTag'=>'backup'),
    true
    );
    ?>
    `
    Please add the instructions for the CRON job if you do get this going.
Sign In or Register to comment.