Plugin Directory

Changeset 2861721


Ignore:
Timestamp:
02/07/2023 08:44:12 PM (3 years ago)
Author:
zoneit
Message:
  • Added Backups List
  • Restore Backup
Location:
zoneit-backup
Files:
46 added
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • zoneit-backup/trunk/readme.txt

    r2825889 r2861721  
    33Tags: local backup, create backup, zoneit backup, db backup, wordpress backup, wpbackup, wp backup
    44Requires at least: 5.0
    5 Tested up to: 6.1.1
    6 Stable tag: 1.0.1
     5Tested up to: 6.1
     6Stable tag: 1.1
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1515
    1616You Can use this plugin for migrating your website to Zoneit Cloud.
     17
     18Features:
     19- Create Backup - manually
     20- View And Delete Backups List
     21- Restore Backup
    1722
    1823== Installation ==
     
    3742== Changelog ==
    3843
    39 = 1.0.1 =
    40 * Added zoneit cloud api service
     44= 1.1 =
     45* Added backups list
     46* Added restore action for every backup
    4147
    4248= 1.0 =
     
    4551== Upgrade Notice ==
    4652
     53= 1.1 =
     54* Added backups list
     55* Added restore action for every backup
     56
    4757= 1.0 =
    4858* launch first version
  • zoneit-backup/trunk/zoneit-backup.php

    r2825889 r2861721  
    11<?php
    22/*
    3 Plugin Name: ZoneIT Backup
     3Plugin Name: Zoneit Backup
    44Description: This plugin is creating a backup from website files and db
    5 Version: 1.0.1
     5Version: 1.1
    66Author: Zoneit Cloud
    77Author URI: https://zoneit.cloud
    88License: GPL-2.0+
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
    10 Domain Path: /lang
     10Domain Path: /;anguages
    1111Text Domain: zoneit-backup
    1212*/
     
    2626        {
    2727            define('ZONEIT_BACKUP_DIR', ABSPATH.'backup/' );
    28             define('ZONEIT_BACKUP_URL', get_site_url().'/backup/' );
    29            
    30             // create backup
    31             add_action( 'zoneit_backup_create_backup', array(&$this, 'create_backup') );
     28            define('ZONEIT_BACKUP_URL', get_site_url().'/backup/' );
     29            define('ZONEIT_BACKUP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
     30            define('ZONEIT_BACKUP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
     31            define('ZONEIT_DB_PREFIX', 'zoneit_');
    3232
    33             // zoneit backup settings
    34             require_once('includes/class.settings.php');
     33            // delete option in new version
     34            delete_option('zoneit_backup_urls');
    3535
    36             // zoneit backup api route
    37             require_once('includes/class.rest-api.php');
     36            // include
     37            require_once 'includes/class-backup-core.php';
     38            require_once 'includes/services/class-backup-service.php';
     39            require_once 'includes/class-backups-list.php';
     40            require_once 'includes/class-cron-backup.php';
     41            require_once 'includes/class-restore-core.php';
     42            require_once 'includes/class-settings.php';
     43           
     44            // zoneit backup api route
     45            require_once('includes/class-rest-api.php');
    3846           
    3947        } // END public function __construct()
    4048       
    41         /**
    42         * create backup from db
    43         * @param void
    44         * @return mysql_dump_url
    45         */
    46         public static function zoneit_db_dump()
    47         {
    48             ini_set('max_execution_time', '0');
    49 
    50             require_once('vendor/autoload.php');
    51             $file_name = 'zoneit_db_'.md5(sha1("Zoneit".get_site_url()."BackUp")).'_'.date("Ymd").'.sql';
    52 
    53             if(!is_dir( ZONEIT_BACKUP_DIR ))
    54                 mkdir( ZONEIT_BACKUP_DIR );
    55 
    56             if(file_exists( ZONEIT_BACKUP_DIR . $file_name ) )
    57                 unlink( ZONEIT_BACKUP_DIR . $file_name );
    58            
    59             try {
    60                 $dump = new \Ifsnop\Mysqldump\Mysqldump('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASSWORD);
    61                 $dump->start( ZONEIT_BACKUP_DIR . $file_name );
    62                 return ZONEIT_BACKUP_URL . $file_name;
    63             } catch (\Exception $e) {
    64                 //return 'mysqldump-php error: ' . $e->getMessage();
    65                 return '';
    66             }
    67         }
    68        
    69         /**
    70         * create zip backup from files
    71         * @param void
    72         * @return zip_archive_url
    73         */
    74         public static function zoneit_file_archive()
    75         {
    76             ini_set('max_execution_time', '0');
    77            
    78             // Get real path for our folder
    79             $rootPath = realpath( ABSPATH );
    80             $file_name = 'zoneit_archive_'.md5(sha1("Zoneit".get_site_url()."BackUp")).'_'.date("Ymd").'.zip';
    81            
    82             if( file_exists( ZONEIT_BACKUP_DIR . $file_name ) )
    83                 unlink( ZONEIT_BACKUP_DIR . $file_name );
    84            
    85             // Initialize archive object
    86             $zip = new ZipArchive();
    87             $zip->open( ZONEIT_BACKUP_DIR . '/' . $file_name , ZipArchive::CREATE | ZipArchive::OVERWRITE);
    88            
    89             // Create recursive directory iterator
    90             /** @var SplFileInfo[] $files */
    91             $files = new RecursiveIteratorIterator(
    92                 new RecursiveDirectoryIterator($rootPath),
    93                 RecursiveIteratorIterator::LEAVES_ONLY
    94             );
    95            
    96             foreach ($files as $name => $file)
    97             {
    98                 // Skip directories (they would be added automatically)
    99                 if (!$file->isDir())
    100                 {
    101                     // Get real and relative path for current file
    102                     $filePath = $file->getRealPath();
    103                     $relativePath = substr($filePath, strlen($rootPath) + 1);
    104                    
    105                     // Add current file to archive
    106                     $zip->addFile($filePath, $relativePath);
    107                 }
    108             }
    109            
    110             // Zip archive will be created only after closing object
    111             $zip->close();
    112             if( file_exists( ZONEIT_BACKUP_DIR . $file_name ) )
    113                 return ZONEIT_BACKUP_URL . $file_name;
    114             else
    115                 return '';
    116         }
    117 
    118         /**
    119          * Create MySQL Dump and zip archive files using cron job
    120          */
    121         public static function run_backup_event()
    122         {
    123             if( !wp_next_scheduled( 'zoneit_backup_create_backup' ) )
    124             {
    125                 wp_schedule_single_event( time(), 'zoneit_backup_create_backup');
    126             }
    127         }
    128 
    129         /**
    130          * Create MySQL Dump and zip archive files using cron job
    131          *
    132          */
    133         public static function create_backup()
    134         {
    135             $zoneit_backup = get_option('zoneit_backup_urls');
    136 
    137             $zoneit_backup['status'] = true;
    138 
    139             // db dump file
    140             $db_dump_file_url = self::zoneit_db_dump();
    141             if( !empty( $db_dump_file_url ) )
    142             {
    143                 $zoneit_backup['db'] = $db_dump_file_url;
    144             }
    145 
    146             // archive file
    147             $archive_file_url = self::zoneit_file_archive();
    148             if( !empty( $archive_file_url ) )
    149             {
    150                 $zoneit_backup['archive'] = $archive_file_url;
    151             }
    152 
    153             // update option
    154             update_option('zoneit_backup_urls', $zoneit_backup );
    155 
    156             // final request to zoneit endpoint
    157             Zoneit_Backup_REST_API::connect_zoneit_api();
    158         }
    159 
    160         /**
    161          * Get backup links
    162          * @param void
    163          * @return backup_urls
    164          */
    165         public static function get_backup_urls()
    166         {
    167             $backup_urls = [];
    168             $backup_urls = get_option('zoneit_backup_urls');
    169 
    170             // remove db url before return
    171             unset($backup_urls['db']);
    172 
    173             return $backup_urls;
    174         }
    175 
    17649        /**
    17750         * Activate the plugin
Note: See TracChangeset for help on using the changeset viewer.