86400, 'weekly' => 604800, 'monthly' => 2592000, ); if ( $_POST['s3b-schedule'] != 'disabled' ) { if ( get_option('s3b-schedule') != $_POST['s3b-schedule'] ) { wp_clear_scheduled_hook('s3-backup'); wp_schedule_event(time() + $schedules[$_POST['s3b-schedule']], $_POST['s3b-schedule'], 's3-backup', array(false)); } } else { wp_clear_scheduled_hook('s3-backup'); } if ( $_POST['Submit'] == 'Save Changes and Backup Now' ) { wp_schedule_single_event(time(), 's3-backup', array(true)); } } if ( isset($_POST['s3-new-bucket']) && !empty($_POST['s3-new-bucket']) ) { include_once 'S3.php'; $settings = self::get_settings(); $_POST['s3-new-bucket'] = strtolower($_POST['s3-new-bucket']); $s3 = new S3($settings['access-key'], $settings['secret-key']); $s3->putBucket($_POST['s3-new-bucket']); $buckets = $s3->listBuckets(); if ( is_array($buckets) && in_array($_POST['s3-new-bucket'], $buckets) ) { update_option('s3b-bucket', $_POST['s3-new-bucket']); $_POST['s3b-bucket'] = $_POST['s3-new-bucket']; } else { update_option('s3b-bucket', ''); $_POST['s3b-bucket'] = ''; } } if ( !get_option('s3b-bucket') ) add_action('admin_notices', array('cmAWB','newBucketWarning')); } function newBucketWarning() { echo "

".__('You need to select a valid S3 bucket.', 'automatic-wordpress-backup')." ".__('If you tried to create a new bucket, it may have been an invalid name.', 'automatic-wordpress-backup').' | '.__('Plugin Settings', 'automatic-wordpress-backup').'

'; } /** * Return the filesystem path that the plugin lives in. * * @return string */ function getPath() { return dirname(__FILE__) . '/'; } /** * Returns the URL of the plugin's folder. * * @return string */ function getURL() { return WP_CONTENT_URL.'/plugins/'.basename(dirname(__FILE__)) . '/'; } /** * Returns the URL of the plugin's settings page. * * @return string */ function get_plugin_page($full = false) { global $wp_version; if ( !$full ) { return 'admin.php?page=' . plugin_basename(__FILE__); } } /** * Sets up the settings page * */ function add_settings_page() { load_plugin_textdomain('automatic-wordpress-backup', cmAWB::getPath() . 'i18n'); add_submenu_page('wdc-settings', __('Automatic Backup', 'automatic-wordpress-backup'), __('Automatic Backup', 'automatic-wordpress-backup'), 8, __FILE__, array('cmAWB', 'settings_page')); } /** * Generates the settings page * */ function settings_page() { include_once 'S3.php'; $sections = get_option('s3b-section'); if ( !$sections ) { $sections = array(); } $settings = self::get_settings(); ?>

/>

/>

How would you like to support us?

We've put some serious time, money and energy into making this plugin and are constantly improving it to ensure you have a safe website. In order to help keep the plugin free and constantly improving, we ask that you do your part by supporting us by allowing us to add a short credits link into the footer or by writing a review of plugin when you're ready.



PS: If the default credit message doesn't look right in your theme,
email us and we'll make it look great at no cost to you.

listBuckets(); ?>









the next time you view this page.", 'automatic-wordpress-backup'), self::get_plugin_page() ); } } } ?>

Download recent backups

getBucket(get_option('s3b-bucket'), next(explode('//', get_bloginfo('siteurl')))); krsort($backups); $count = 0; foreach ( $backups as $key => $backup ) { $backup['label'] = sprintf(__('WordPress Backup from %s', 'automatic-wordpress-backup'), mysql2date(__('F j, Y h:i a'), date('Y-m-d H:i:s', $backup['time'] + (get_option('gmt_offset') * 3600)))); if ( preg_match('|[0-9]{4}\.zip$|', $backup['name']) ) { $backup['label'] = sprintf(__('Manual WordPress Backup from %s', 'automatic-wordpress-backup'), mysql2date(__('F j, Y h:i a'), date('Y-m-d H:i:s', $backup['time'] + (get_option('gmt_offset') * 3600)))); } elseif ( preg_match('|[0-9]{4}\.uploads\.zip$|', $backup['name']) ) { $backup['label'] = sprintf(__('Manual Uploads Backup from %s', 'automatic-wordpress-backup'), mysql2date(__('F j, Y h:i a'), date('Y-m-d H:i:s', $backup['time'] + (get_option('gmt_offset') * 3600)))); } elseif ( preg_match('|\.uploads\.zip$|', $backup['name']) ) { $backup['label'] = sprintf(__('Uploads Backup from %s', 'automatic-wordpress-backup'), mysql2date(__('F j, Y h:i a'), date('Y-m-d H:i:s', $backup['time'] + (get_option('gmt_offset') * 3600)))); } $backup = apply_filters('s3b-backup-item', $backup); if ( ++$count > 40 ) break; ?>
0, 'cleanup-save-monthly' => 0, 'cleanup-save-manual' => 0, 'access-key' => null, 'secret-key' => null, ), $settings); if ( defined('AWB_ACCESS_KEY') ) $settings['access-key'] = AWB_ACCESS_KEY; if ( defined('AWB_SECRET_KEY') ) $settings['secret-key'] = AWB_SECRET_KEY; return $settings; } function backup($manual = false) { global $wpdb; require_once('S3.php'); require_once(ABSPATH . '/wp-admin/includes/class-pclzip.php'); $settings = self::get_settings(); $s3 = new S3($settings['access-key'], $settings['secret-key']); $site = next(explode('//', get_bloginfo('siteurl'))); if ( isset($settings['cleanup']) && $settings['cleanup'] ) { $backups = $s3->getBucket(get_option('s3b-bucket'), $site); ksort($backups); $months = array(); $_month = strtotime("-1 month"); $_year = strtotime("-1 year"); foreach ( $backups as $key => $backup ) { if ( preg_match('|[0-9]{4}\.zip$|', $backup['name']) ) { if ( !$settings['cleanup-save-manual'] && $_month > $backup['time'] ) { $s3->deleteObject(get_option('s3b-bucket'), $backup['name']); } } else { $month = date('Ym', $backup['time']); if ( $settings['cleanup-save-monthly'] && $_year < $backup['time'] && !in_array($month, $months) ) { $months[] = $month; } elseif ( $_month > $backup['time'] ) { $s3->deleteObject(get_option('s3b-bucket'), $backup['name']); } } } } $sections = get_option('s3b-section'); if ( !$sections ) { $sections = array(); } $file = WP_CONTENT_DIR . '/uploads/automatic-wordpress-backup.zip'; $cwd = getcwd(); chdir(ABSPATH); $backups = array(); if ( in_array('config', $sections) ) { $backups[] = ABSPATH . 'wp-config.php'; if ( is_file(ABSPATH . '.htaccess') ) { $backups[] = ABSPATH . '.htaccess'; } } if ( in_array('database', $sections) ) { $tables = $wpdb->get_col("SHOW TABLES LIKE '" . $wpdb->prefix . "%'"); $result = shell_exec('mysqldump --add-drop-table --single-transaction -h ' . DB_HOST . ' -u ' . DB_USER . ' --password="' . DB_PASSWORD . '" ' . DB_NAME . ' ' . implode(' ', $tables) . ' > ' . WP_CONTENT_DIR . '/uploads/wp-s3-database-backup.sql'); $backups[] = WP_CONTENT_DIR . '/uploads/wp-s3-database-backup.sql'; } if ( in_array('themes', $sections) ) $backups[] = WP_CONTENT_DIR . '/themes'; if ( in_array('plugins', $sections) ) $backups[] = WP_CONTENT_DIR . '/plugins'; if ( in_array('uploads', $sections) ) $backups[] = WP_CONTENT_DIR . '/uploads'; if ( !empty($backups) ) { foreach ( $backups as $key => $value ) { $backups[$key] = str_replace(ABSPATH, '', $value); } $result = shell_exec('zip -r ' . $file . ' ' . implode(' ', $backups)); $upload = $s3->inputFile($file); if ( $manual ) { $s3->putObject($upload, get_option('s3b-bucket'), next(explode('//', get_bloginfo('siteurl'))) . '/' . date('Y-m-d-Hi') . '.zip'); } else { $s3->putObject($upload, get_option('s3b-bucket'), next(explode('//', get_bloginfo('siteurl'))) . '/' . date('Y-m-d') . '.zip'); } @unlink($file); @unlink(WP_CONTENT_DIR . '/uploads/wp-s3-database-backup.sql'); } chdir($cwd); } function cron_schedules($schedules) { $schedules['weekly'] = array('interval'=>604800, 'display' => 'Once Weekly'); $schedules['monthly'] = array('interval'=>2592000, 'display' => 'Once Monthly'); return $schedules; } function settings_link($links) { $settings_link = '' . __('Settings', 'automatic-wordpress-backup') . ''; array_unshift( $links, $settings_link ); return $links; } function wdc_plugins($plugins) { if ( is_array($plugins) ) { $plugins[] = 'Automatic WordPress Backup v1.0'; } return $plugins; } } add_filter('cron_schedules', array('cmAWB', 'cron_schedules')); add_action('admin_menu', array('cmAWB', 'add_settings_page')); add_action('s3-backup', array('cmAWB', 'backup'), 1); add_action('init', array('cmAWB', 'init')); add_filter("plugin_action_links_" . plugin_basename(__FILE__), array('cmAWB', 'settings_link') ); add_filter('wdc_plugins', array('cmAWB', 'wdc_plugins')); ?>