Backup and Restore WordPress – WPBackItUp Backup Plugin - Version 1.0.6

Version Description

  • Initial free version of the plugin distributed on Wordpress. This version can only backup.
Download this release

Release Info

Developer jcpeden
Plugin Icon 128x128 Backup and Restore WordPress – WPBackItUp Backup Plugin
Version 1.0.6
Comparing to
See all releases

Version 1.0.6

backups/status.log ADDED
@@ -0,0 +1 @@
 
1
+ <ul><li>Creating backup directory...Done!</li><li>Backing up your files...Done!</li><li>Backing up your database...Done!</li><li>Creating backup zip...Done!</li><li>Backup file created successfully. You can download your backup file using the link above.</li></ul>
css/wp-backitup.css ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* WP Backitup CSS */
2
+
3
+ .error { color: #ff0000;}
4
+
5
+ input {padding: 0;}
6
+
7
+ h3 {
8
+ margin: 0;
9
+ padding: 1em 0 0 0;
10
+ }
11
+
12
+ ul {padding: 1em 0 0 0;}
13
+
14
+ iframe {
15
+ height: 0;
16
+ margin: 0;
17
+ padding: 0;
18
+ position: absolute;
19
+ top: 0;
20
+ right: 0;
21
+ width: 0;
22
+ }
23
+
24
+ .wp-backitup-section {clear:both;}
25
+
26
+ #backup-button, #restore-form {
27
+ float: left;
28
+ margin: 0 5px 5px 0;
29
+ }
30
+
31
+ #backup-button a {
32
+ display: block;
33
+ padding: 3px 8px;
34
+ -webkit-border-radius: 10px;
35
+ -moz-border-radius: 10px;
36
+ border-radius: 10px;
37
+ }
38
+
39
+ .status-icon {
40
+ display: inline;
41
+ height: 16px;
42
+ visibility: hidden;
43
+ width: 16px;
44
+ }
45
+
46
+ .status-icon img {margin-top: 3px;}
47
+
48
+ #wp-backitup-restore .status-icon img {margin-top: 7px;}
49
+
50
+ #restore_form {margin-right: 5px;}
51
+
52
+ #restore-button {margin-top: 22px;}
images/loader.gif ADDED
Binary file
includes/admin_page.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
includes/backup.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // 5 minutes per image should be PLENTY
3
+ @set_time_limit(900);
4
+
5
+ //Define variables
6
+ $backup_project_dirname = get_bloginfo('name') .'-Export-' .date('Y-m-d-Hi');
7
+ $backup_project_path = BACKUP_PATH .$backup_project_dirname .'/';
8
+ $wp_content_path = dirname(dirname(dirname(dirname(__FILE__)))) .'/';
9
+
10
+ //create log file
11
+ $log = BACKUP_PATH . "status.log";
12
+ $fh = fopen($log, 'w') or die("can't open file");
13
+ fwrite($fh, '<ul>');
14
+
15
+ //Check to see if the directory is writeable
16
+ fwrite($fh, '<li>Creating backup directory...');
17
+ if(!is_writeable(BACKUP_PATH)) {
18
+ fwrite($fh, '</li><li class="error">Cannot create backup directory. Please check the CHMOD settings of your wp-backitup plugin directory.</li></ul>');
19
+ die();
20
+ } else {
21
+ //If the directory is writeable, create the backup folder if it doesn't exist
22
+ if( !is_dir($backup_project_path) ) {
23
+ @mkdir($backup_project_path, 0755);
24
+ fwrite($fh, 'Done!</li>');
25
+ }
26
+ foreach(glob(BACKUP_PATH . "*.zip") as $zip) {
27
+ unlink($zip);
28
+ }
29
+ }
30
+
31
+ //Backup content to project dir
32
+ fwrite($fh, '<li>Backing up your files...');
33
+ //Backup with copy
34
+ if(recursive_copy($wp_content_path, $backup_project_path, $ignore = array( 'cgi-bin','.','..','._',$backup_project_dirname ) ) ) {
35
+ fwrite($fh, 'Done!</li>');
36
+ } else {
37
+ fwrite($fh, '</li><li class="error">Unable to backup your files. Please try again.</li></ul>');
38
+ die();
39
+ }
40
+
41
+ //Dump DB to project dir
42
+ fwrite($fh, '<li>Backing up your database...');
43
+ if( db_backup($backup_project_path) ) {
44
+ fwrite($fh, 'Done!</li>');
45
+ } else {
46
+ fwrite($fh, '</li><li class="error">Unable to backup your database. Please try again.</li></ul>');
47
+ recursive_delete($backup_project_path);
48
+ die();
49
+ }
50
+
51
+ //Create siteinfo in project dir
52
+ global $wpdb;
53
+ if (!create_siteinfo($backup_project_path, $wpdb->prefix) ) {
54
+ fwrite($fh, '<li class="error">Unable to create site information file. Please try again.</li></ul>');
55
+ recursive_delete($backup_project_path);
56
+ die();
57
+ }
58
+
59
+ //Zip the project dir
60
+ fwrite($fh, '<li>Creating backup zip...');
61
+ require(WPBACKITUP_PLUGIN_PATH .'includes/recurse_zip.php');
62
+ $z = new recurseZip();
63
+ $src = rtrim($backup_project_path, '/');
64
+ $z->compress($src, BACKUP_PATH);
65
+ fwrite($fh, 'Done!</li>');
66
+
67
+ //Delete backup dir
68
+ if(!recursive_delete($backup_project_path)) {
69
+ fwrite($fh, '<li class="error">Warning: Unable to cleanup your backup directory.</li>');
70
+ }
71
+
72
+ //close log file
73
+ fwrite($fh, '<li>Export file created successfully. You can download your export file using the link above.</li>');
74
+ fwrite($fh, '</ul>');
75
+ fclose($fh);
76
+
77
+ //End backup function
78
+ die();
includes/download.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ //Define variables
3
+ $wp_backitup_path = dirname(dirname(__FILE__));
4
+ $wp_content_dirname = basename(dirname(dirname(dirname(dirname(__FILE__)))));
5
+ $wp_backitup_dirname = basename($wp_backitup_path);
6
+
7
+ //build download link
8
+ if(glob($wp_backitup_path . "/backups/*.zip")) {
9
+ echo '<ul>';
10
+ foreach (glob($wp_backitup_path . "/backups/*.zip") as $file) {
11
+ $filename = basename($file);
12
+ echo '<li>Download most recent export file: <a href="' .site_url() .'/' .$wp_content_dirname .'/' .'plugins/' .$wp_backitup_dirname. '/backups/' .$filename .'">' .$filename .'</a></li>';
13
+ }
14
+ echo '</ul>';
15
+ } else {
16
+ echo '<p>No export file available for download. Please create one.</p>';
17
+ }
18
+ die();
includes/functions.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php //Define the create_dir function
2
+ if(!function_exists('create_dir')) {
3
+ function create_dir($dir) {
4
+ if( !is_dir($dir) ) {
5
+ @mkdir($dir, 0755);
6
+ }
7
+ return true;
8
+ }
9
+ }
10
+
11
+ //Define recusive_copy function
12
+ if(!function_exists('recursive_copy')) {
13
+ function recursive_copy($dir, $target_path, $ignore = array( 'cgi-bin','..','._' ) ) {
14
+ if( is_dir($dir) ) { //If the directory exists
15
+ if ($dh = opendir($dir) ) {
16
+ while(($file = readdir($dh)) !== false) { //While there are files in the directory
17
+ if ( !in_array($file, $ignore) && substr($file, 0, 1) != '.') { //Check the file is not in the ignore array
18
+ if (!is_dir( $dir.$file ) ) { //If $file is a file
19
+ //Copy files to destination directory
20
+ $fsrc = fopen($dir .$file,'r');
21
+ $fdest = fopen($target_path .$file,'w+');
22
+ $len = stream_copy_to_stream($fsrc,$fdest);
23
+ fclose($fsrc);
24
+ fclose($fdest);
25
+ } else { //If $file is a directory
26
+ $destdir = $target_path .$file; //Modify the destination dir
27
+ if(!is_dir($destdir)) { //Create the destdir if it doesn't exist
28
+ @mkdir($destdir, 0755);
29
+ }
30
+ recursive_copy($dir .$file .'/', $target_path .$file .'/', $ignore);
31
+ }
32
+ }
33
+ }
34
+ closedir($dh);
35
+ }
36
+ }
37
+ return true;
38
+ }
39
+ }
40
+
41
+ //Define DB backup function
42
+ if(!function_exists('db_backup')) {
43
+ function db_backup($path) {
44
+ global $wpdb;
45
+ $row = $wpdb->get_results('SHOW TABLES', ARRAY_N);
46
+ $tables = array();
47
+ foreach($row as $value) {
48
+ $tables[] = $value[0];
49
+ }
50
+ $handle = fopen($path .'db-backup.sql', 'w+');
51
+ foreach($tables as $table) {
52
+ $result = $wpdb->get_results('SELECT * FROM '.$table,ARRAY_N);
53
+ $testing = $wpdb->get_row('SELECT * FROM '.$table,ARRAY_N);
54
+ $num_fields=count($testing);
55
+ $return = '';
56
+ $return.= 'DROP TABLE IF EXISTS '.$table.';';
57
+ $row2 = $wpdb->get_row('SHOW CREATE TABLE '.$table,ARRAY_N);
58
+ $return.= "\n\n".$row2[1].";\n\n";
59
+ foreach($result as $row) {
60
+ $return.= 'INSERT INTO '.$table.' VALUES(';
61
+ for($j=0; $j<$num_fields; $j++) {
62
+ $row[$j] = addslashes($row[$j]);
63
+ $row[$j] = ereg_replace("\n", "\\n",$row[$j]);
64
+ if (isset($row[$j])) {
65
+ $return .= '"' .$row[$j] .'"';
66
+ } else {
67
+ $return .= '"';
68
+ }
69
+ if ($j<($num_fields-1)) { $return.= ', '; }
70
+ }
71
+ $return.= ");\n";
72
+ }
73
+ $return.="\n\n\n";
74
+ fwrite($handle, $return);
75
+ }
76
+ fclose($handle);
77
+ return true;
78
+ }
79
+ }
80
+
81
+ //Define the create_siteinfo function
82
+ if(!function_exists('create_siteinfo')) {
83
+ function create_siteinfo($path, $table_prefix) {
84
+ $siteinfo = $path ."backupsiteinfo.txt";
85
+ $handle = fopen($siteinfo, 'w+');
86
+ $entry = site_url( '/' ) ."\n$table_prefix";
87
+ fwrite($handle, $entry);
88
+ fclose($handle);
89
+ return true;
90
+ }
91
+ }
92
+
93
+ //Define recursive_delete function
94
+ if(!function_exists('recursive_delete')){
95
+ function recursive_delete($dir, $ignore = array('cgi-bin','.','..','._') ){
96
+ if( is_dir($dir) ){
97
+ if($dh = opendir($dir)) {
98
+ while( ($file = readdir($dh)) !== false ) {
99
+ if (!in_array($file, $ignore) && substr($file, 0, 1) != '.') { //Check the file is not in the ignore array
100
+ if(!is_dir($dir .'/'. $file)) {
101
+ unlink($dir .'/'. $file);
102
+ } else {
103
+ recursive_delete($dir.'/'. $file, $ignore);
104
+ }
105
+ }
106
+ }
107
+ }
108
+ @rmdir($dir);
109
+ closedir($dh);
110
+ }
111
+ return true;
112
+ }
113
+ }
includes/recurse_zip.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php
js/wp-backitup.js ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($) {
2
+ //define backup variables
3
+ var wpBackitupBackup = {
4
+ action: 'wpbackitup_backup',
5
+ beforeSend: function() {
6
+ $('#wp-backitup-backup .status-icon').css('visibility','visible');
7
+ $("#wp-backitup-status").empty();
8
+ setInterval(logreader, 1000);
9
+ }
10
+ };
11
+
12
+ //define download variables
13
+ var wpBackitupDownload = {
14
+ action: 'wpbackitup_download'
15
+ };
16
+
17
+ //define logreader variables
18
+ var wpBackitupLogReader = {
19
+ action: 'wpbackitup_logreader'
20
+ };
21
+
22
+ //define logreader function
23
+ function logreader() {
24
+ $.post(ajaxurl, wpBackitupLogReader, function(response) {
25
+ $("#wp-backitup-status").html(response);
26
+ });
27
+ }
28
+
29
+ //define download function
30
+ function download() {
31
+ $.post(ajaxurl, wpBackitupDownload, function(response) {
32
+ $("#wp-backitup-download-status").html(response);
33
+ });
34
+ }
35
+
36
+ //execute download (on page load/refresh)
37
+ download();
38
+
39
+ //execute backup on button click
40
+ $("#wpBackitupBackup").click( function() {
41
+ $.post(ajaxurl, wpBackitupBackup, function(response) {
42
+ download(); //Build download link
43
+ clearInterval(logreader); //Stop checking for status updates
44
+ $('#wp-backitup-backup .status-icon').fadeOut(1000); //Fade process indicator
45
+ $("#wp-backitup-php").html(response); //Return PHP messages, used for development
46
+ });
47
+ })
48
+ });
readme.txt ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: jcpeden
3
+ Donate link: http://www.wpBackitup.com
4
+ Tags: backup, restore, clone, database, wp-content, files
5
+ Requires at least: 3.4
6
+ Tested up to: 3.5
7
+ Stable tag: 1.0.6
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ WP Backitup allows you to backup your database and wp-content folder. This allows you to quickly clone, backup and restore any of your Wordpress sites.
12
+
13
+ == Description ==
14
+
15
+ WP Backitup uses nothing but PHP to allow you to backup and restore your Wordpress database, plugins, themes and uploads directories. You can create a
16
+ backup of any site and, using WP Backitup, quickly import your files, settings and content into a new site.
17
+
18
+ == Installation ==
19
+
20
+ Installation of the plugin is straightforward:
21
+
22
+ 1. Upload the directory `wp-Backitup` to the `/wp-content/plugins/` directory.
23
+ 1. Activate the plugin through the `Plugins` menu in WordPress.
24
+ 1. Through the Wordpress dashboard, browse to Tools > WP Backitup.
25
+
26
+ == Frequently Asked Questions ==
27
+
28
+ = Will the plugin work on shared hosting/sub domains/webhost xxx? =
29
+ Yes
30
+
31
+ = Will WP Backitup work on Windows hosting? =
32
+ Yes
33
+
34
+ = Are you going to be making progress bars both for backing up and restoring with this plugin? =
35
+ Not at this time.
36
+
37
+ = Can this plugin back to Amazon S3? =
38
+ Not at this time.
39
+
40
+ = Is there an auto back up schedule feature? =
41
+ Not at this time.
42
+
43
+ = Will the plugin work with Wordpres version x.x? =
44
+ The plugin works on the latest release of WordPress and is updated to function with all new releases.
45
+
46
+ = Can this backup one version of WordPress to a different version? =
47
+ No. It is absolutely critical that your WordPress versions are exactly the same.
48
+
49
+ = Will WP Backitup work on WordPress Multisite? =
50
+ It is untested with Wordpress multisite and probably will not work.
51
+
52
+ = Does the plugin copy the database details as well? =
53
+ Yes, a database dump is created with each backup.
54
+
55
+ = Can I make a basic WordPress site, with all my desired plugins and settings, make a few pages, setup permalinks, remove all the default junk and load in a basic themplate? =
56
+ Yes. WP Backitup can be used to create a good starting point for any and all sites you work on.
57
+
58
+ = Does WP Backitup need to be installed? =
59
+ Yes. You must install the WP Backitup plugin on the site you wish to backup and the site you wish to restore to. Its just a simple plugin.
60
+
61
+ = Does WP Backitup backup plugins settings or just the plugins themselves? =
62
+ WP Backitup creates a database dump and a backup of all your themes, plugins and uploads.
63
+
64
+ = Do you have any ideas about how large a blog is too big for WP Backitup to handle? =
65
+ I`ve tested up to 5 themes, 20 plugins and 100 posts/pages without any issues.
66
+
67
+ = Do you do regularly update this product to match with WP version updates? =
68
+ Yes.
69
+
70
+ == Screenshots ==
71
+ 1. Once activated, the plugin loads a new menu into Tools > WP Backitup.
72
+ 2. Simply click 'Export' to generate a backup of your site. The plugin will update you on its progress.
73
+ 3. When the backup has been created, click the download link to access a zipped backup of your site.
74
+
75
+ == Changelog ==
76
+
77
+ = 1.0.6 =
78
+ * Initial free version of the plugin distributed on Wordpress. This version can only backup.
79
+
80
+ = 1.0.5 =
81
+ * Modified backup to use AJAX and restore to use AJAX-like functionality. Added read-write for options so they are saved to DB on exit.
82
+
83
+ = 1.0.4 =
84
+ * Reduced the size of the plugin by re-using code. Added support for multiple table prefixes and media library import.
85
+
86
+ = 1.0.3 =
87
+ * Removed redundant code, allowed plugin to work with multiple table prefixes and user IDs other than 1.
88
+
89
+ = 1.0.2 =
90
+ * Fixed backup/restore function of database, plugins and themes dir. Removed PHP error notices if options are not set on admin page
91
+
92
+ = 1.0.1 =
93
+ * Increased PHP timeout to 900 seconds (5 minutes).
94
+
95
+ = 1.0 =
96
+ * Plugin released.
97
+
98
+ == Upgrade Notice ==
99
+
100
+ = 1.0.6 =
101
+ * Non-critical upgrade.
102
+
103
+ = 1.0.5 =
104
+ * Critical upgrade: More stable, increased flexibility and power.
105
+
106
+ = 1.0.4 =
107
+ * Critical upgrade: Many people have had trouble prior to this release. Flexibility has been increased and the plugin is now more stable and lightweight.
108
+
109
+ = 1.0.3 =
110
+ * Recommended upgrade: The plugin is more flexible and offers more helpful status and error messages.
111
+
112
+ = 1.0.2 =
113
+ * Critical upgrade: Plugin does not work on most systems without this upgrade
114
+
115
+ = 1.0.1 =
116
+ * This version increases PHP timeout if possible (upgrade if you are having timeout errors).
117
+
118
+ = 1.0 =
119
+ Initial version of the plugin.
wp-backitup.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: WP Backitup
4
+ * Plugin URI: http://www.wpbackitup.com
5
+ * Description: Backup your content, settings, themes, plugins and media in just a few simple clicks.
6
+ * Version: 1.0.6
7
+ * Author: John Peden
8
+ * Author URI: http://www.johncpeden.com
9
+ * License: GPLv2 or later
10
+ * Text Domain: wp-backitup
11
+ */
12
+
13
+ /*
14
+ Copyright 2012-current John C. Peden ( email : mail@johncpeden.com )
15
+ */
16
+
17
+ //define constants
18
+ define("WPBACKITUP_PLUGIN_URL", WP_PLUGIN_URL ."/wp-backitup/");
19
+ define("WPBACKITUP_PLUGIN_PATH", WP_PLUGIN_DIR."/wp-backitup/");
20
+ define("WPBACKITUP_DIRNAME", "wp-backitup");
21
+ define("BACKUP_PATH", WPBACKITUP_PLUGIN_PATH .'backups/');
22
+
23
+ //add plugin options
24
+ function wpbackitup_options_init() {
25
+ register_setting ('wpbackitup_options', 'wpbackitup', 'wpbackitup_options_validate');
26
+ }
27
+ add_action('admin_init', 'wpbackitup_options_init' );
28
+
29
+ //load admin menu
30
+ function wpbackitup_admin_menus() {
31
+ $wpbackituppage = add_submenu_page( 'tools.php', 'WP BackItUp', 'WP BackItUp', 'manage_options', 'wp-backitup', 'wpbackitup_admin' );
32
+ add_action('admin_print_scripts-'.$wpbackituppage, 'wpbackitup_javascript');
33
+ add_action('admin_print_styles-' .$wpbackituppage, 'wpbackitup_stylesheet' );
34
+ }
35
+ add_action('admin_menu', 'wpbackitup_admin_menus');
36
+
37
+ //enqueue javascript
38
+ function wpbackitup_javascript() {
39
+ wp_enqueue_script('wpbackitup-javascript', WPBACKITUP_PLUGIN_URL.'/js/wp-backitup.js');
40
+ wp_enqueue_script('ajaxfileupload', WPBACKITUP_PLUGIN_URL.'/js/ajaxfileupload.js');
41
+ }
42
+
43
+ //enqueue stylesheet
44
+ function wpbackitup_stylesheet(){
45
+ wp_enqueue_style('wpbackitup-stylesheet', WPBACKITUP_PLUGIN_URL.'/css/wp-backitup.css');
46
+ }
47
+
48
+ //load plugin functions
49
+ include_once 'includes/functions.php';
50
+
51
+ //load admin page
52
+ function wpbackitup_admin() {
53
+ include_once('includes/admin_page.php');
54
+ }
55
+
56
+ //load backup function
57
+ function wpbackitup_backup() {
58
+ include 'includes/backup.php';
59
+ }
60
+ add_action('wp_ajax_wpbackitup_backup', 'wpbackitup_backup');
61
+
62
+ //load download function
63
+ function wpbackitup_download() {
64
+ include 'includes/download.php';
65
+ }
66
+ add_action('wp_ajax_wpbackitup_download', 'wpbackitup_download');
67
+
68
+ //load download function
69
+ function wpbackitup_logreader() {
70
+ if(file_exists(BACKUP_PATH .'/status.log') ) {
71
+ readfile(BACKUP_PATH .'/status.log');
72
+ }
73
+ die();
74
+ }
75
+ add_action('wp_ajax_wpbackitup_logreader', 'wpbackitup_logreader');