I noticed Snapshots has stopped creating automated backups

Hi,

I noticed Snapshots has stopped creating automated backups (not sure since when) and when I create a new snapshot entry with the "Run immediate" option set, it runs only once but after that "Run now" does nothing.

What's more, it does NOT include media files when the "Include common files: Media" is checked and I notice is that that option says for example:

Include common files:	 Media (varwwwardecheweb.frhtdocswp-contentuploadssites35)

where the upload directory path seems to be missing slashes...

What's that about? Is that related? Another plugin interfering or some server setup issue? The plugin is running on a WordPress 3.9.1 on an Debian 7 + Nginx server.

The matter is a bit urgent because we want to move the installation soon so thanks for any suggestions :slight_smile:

  • RavanH

    Hi @Jack Kitterhing logs did not reveal anything. I tried a Run Now but nothing is created and nothing new added to the log. I tried to set the snapshot to Every 5 Minutes and waited ten minutes, still nothing created and nothing added to the logs.

    Creating a new snaptshot entry with "Include common files" where it says

    Include common files: Media
    (varwwwardecheweb.frhtdocswp-contentuploadssites23)

    and the "Run immediate" option, runs once (showing a list of completed tasks that seems to skip the "Files" part) and creates a zip without Media.

    Log shows:

    2014-07-18 00:27:53: Backup: init
    2014-07-18 00:27:53: adding new snapshot: 1405636038
    2014-07-18 00:27:54: table: wp_23_commentmeta segment: 1/1
    2014-07-18 00:27:54: table: wp_23_comments segment: 1/1
    2014-07-18 00:27:54: table: wp_23_links segment: 1/1
    2014-07-18 00:27:55: table: wp_23_options segment: 1/1
    2014-07-18 00:27:55: table: wp_23_postmeta segment: 1/2
    2014-07-18 00:27:55: table: wp_23_postmeta segment: 2/2
    2014-07-18 00:27:56: table: wp_23_posts segment: 1/1
    2014-07-18 00:27:56: table: wp_23_term_relationships segment: 1/1
    2014-07-18 00:27:57: table: wp_23_term_taxonomy segment: 1/1
    2014-07-18 00:27:57: table: wp_23_terms segment: 1/1
    2014-07-18 00:27:57: table: wp_23_agm_maps segment: 1/1
    2014-07-18 00:27:58: table: wp_23_gde_profiles segment: 1/1
    2014-07-18 00:27:58: table: wp_23_gde_secure segment: 1/1
    2014-07-18 00:27:58: backupZipFolder[]
    2014-07-18 00:27:58: rename: backupZipFile[/var/www/ardecheweb.fr/htdocs/wp-content/uploads/snapshots/_backup/1405636038/snapshot-backup.zip] backupZipFileFinal[/var/www/ardecheweb.fr/htdocs/wp-content/uploads/snapshots/snapshot-1405636038-140717-222718-0131896b.zip]
    2014-07-18 00:27:58: finish: snapshot-1405636038-140717-222718-0131896b.zip
  • RavanH

    On another installation (but similar server setup) I notice this line in one of the logs:

    ...
    2014-07-18 00:48:32: finish: snapshot-1405628203-140717-224828-37f5185b.zip
    2014-07-18 00:48:34: Warning: errno:2 gzinflate(): data error /var/www/7region.fr/htdocs/wp-includes/class-http.php on line 1963

    After this error, no new backups are created... I should mention that on this installation, the media upload path seems correct and media files are included. So this might actually be a different issue. Only similarity is no automatic nor manual snapshots after the first one.

  • RavanH

    Hi @Jack Kitterhing - if it is any help: I found out in which cases Snapshot uses the incorrect file path...

    When using WPMUDEV's Domain Mapping, any site that has one or more mapped domains (I use ALLOW_MULTI) will show this incorrect ( unslashed / absolute ) dir path. This does not happen when using Donccha's Domain Mapping plugin... So the work-around is to temporarily remove the mapped domains before creating a snapshot. Too bad I found this out only AFTER having moved all sites manually :slight_frown:

    Hope that helps getting it fixed sooner :slight_smile:

  • Jack Kitterhing

    Hiya @RavanH,

    Hope you're well today! :slight_smile:

    The automated backups should be resolved with this, it was for a few others, but I believe that path issue is stopping yours from working.

    I've investigated the path issue on my own install and when using domain mapping with the allow multi define, I can replicate the same issue.

    The developer has been notified. Appreciate your patience here. :slight_smile:

    Kind Regards
    Jack.

  • RavanH

    Hi @Rheinard - sorry I never saw your post before. Here is my very late reply:

    I'm using WPMUDEV's Domain Mapping version 4.2.0.1 and Snapshot version 2.4.3.0 on various WordPress 4.0 installations all running on Nginx. All have still the same issue where I need to deactivate Domain Mapping before I can do manual backups for sites that are using a mapped domain.

    So the issue is still there...

    For info: one network (also running on Nginx) is a WP 3.9.2 and uses Donncha's WordPress MU Domain Mapping plugin in combo with Snapshot 2.4.2.3. There, all snapshots work fine for all sites!

    I'll be upgrading that particular network to WP 4.0 and Snapshot 2.4.3.0 tonight and will let you know if snapshots remain working...

  • RavanH

    Hi @Jack - Interesting indeed.... Sadly, I do not have an Apache server to test with. I'll be delving into these three plugins to see if I can make an educated guess about what specific Nginx or PHP5-FPM peculiarities might be at play here.

    @dailyPA - the two domain mapping plugins are not interchangeable. You'll have to deacivate one and then activate and configure the other. Then set up mapping domain for domain, site for site. It's not so difficult but can be a lot of work if you have many sites running...

  • RavanH

    What I found so far:
    In the file snapshot/lib/snapshot_utilities.php inside function snapshot_utility_get_blog_upload_path() there is on line 1056:

    $upload_path = str_replace(get_home_path(), '', $upload_path);

    If I comment out that line, then the upload path that was previously shown as (for example):

    Include common files: Media (varwwwmymultisi.tehtdocswp-contentuploadssites24)

    now becomes:

    Include common files: Media (/var/www/mymultisi.te/htdocs/wp-content/uploads/sites/24)

    I suppose it should actually be "wp-content/uploads/sites/24" in this example because get_home_path() should have returned "/var/www/mymultisi.te/htdocs/" but it appears it simply returns "/" which explains the missing forward slashes...

    Next step: find out why get_home_path() is failing here :slight_smile:

  • RavanH

    This is the weirdest thing I've ever seen... What am I missing?

    Function get_home_path() is a simple one defined in wp-admin/files.php :

    /**
     * Get the absolute filesystem path to the root of the WordPress installation
     *
     * @since 1.5.0
     *
     * @uses get_option
     * @return string Full file system path to the root of the WordPress installation
     */
    function get_home_path() {
    	$home    = set_url_scheme( get_option( 'home' ), 'http' );
    	$siteurl = set_url_scheme( get_option( 'siteurl' ), 'http' );
    	if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) {
    		$wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */
    		$pos = strripos( str_replace( '\\', '/', $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) );
    		$home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos );
    		$home_path = trailingslashit( $home_path );
    	} else {
    		$home_path = ABSPATH;
    	}
    
    	return str_replace( '\\', '/', $home_path );
    }

    A quick test revealed that ABSPATH is not failing, so the issue must lie within the first if block. So I decided to copy the code to inside function snapshot_utility_get_blog_upload_path() to be able to use $home_path directly and debug further.

    Now here's the strange thing: as soon as I integrated the code (without any modifications) into snapshot_utility_get_blog_upload_path() the $home_path string started to return the correct home path instead of "/"

    Whatever could be at play here? The code is exactly the same except for the return part of course.

    So I did another test with mind-blowing results. I copied the snippet to a new function which I placed directly above snapshot_utility_get_blog_upload_path() in snapshot_utilities.php while keeping that snippet inside snapshot_utility_get_blog_upload_path() too. I appended some baboon style echo's for debugging. It now looks like:

    function snapshot_utility_get_home_path() {
    	$home    = set_url_scheme( get_option( 'home' ), 'http' );
    	$siteurl = set_url_scheme( get_option( 'siteurl' ), 'http' );
    	if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) {
    		$wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */
    		$pos = strripos( str_replace( '\\', '/', $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) );
    		$home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos );
    		$home_path = trailingslashit( $home_path );
    	} else {
    		$home_path = ABSPATH;
    	}
    echo "<!-- home_path 2: " . $home_path . " -->";
    
    	return str_replace( '\\', '/', $home_path );
    }
    
    function snapshot_utility_get_blog_upload_path($switched_blog_id=0, $key='basedir') {
    	$home    = set_url_scheme( get_option( 'home' ), 'http' );
    	$siteurl = set_url_scheme( get_option( 'siteurl' ), 'http' );
    	if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) {
    		$wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */
    		$pos = strripos( str_replace( '\\', '/', $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) );
    		$home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos );
    		$home_path = trailingslashit( $home_path );
    	} else {
    		$home_path = ABSPATH;
    	}
    echo "<!-- home_path 1: " . $home_path . " -->";
    
    	global $blog_id;
    ...
    ...
    }

    Now the echo's appearing in page source:

    <!-- home_path 1: /var/www/mymultisi.te/htdocs/ -->
    <!-- home_path 2: / -->

    Is that not amazing? The code used is an exact copy but the outcome is completely different !?!

    It's late, I'm tired and I'm going to bed but I fear this one is going to keep me awake for a while :slight_frown:

    What am I missing?

  • RavanH

    So if I go all out with the echo monkeys, in the routine called AFTER switch_to_blog() like this:

    echo "<!-- home: " . $home . " -->";
    	$siteurl = set_url_scheme( get_option( 'siteurl' ), 'http' );
    echo "<!-- siteurl: " . $siteurl . " -->";
    	if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) {
    		$wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */
    echo "<!-- wp_path_rel_to_home: " . $wp_path_rel_to_home . " -->";
    		$pos = strripos( str_replace( '\\', '/', $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) );
    echo "<!-- pos: " . $pos . " -->";
    		$home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos );
    echo "<!-- home_path a: " . $home_path . " -->";
    		$home_path = trailingslashit( $home_path );
    	} else {
    		$home_path = ABSPATH;
    	}
    echo "<!-- home_path b: " . $home_path . " -->";

    Then the output in source is quite understandably something like this:

    <!-- home: http://mapped-doma.in -->
    <!-- siteurl: http://original.mymultisi.te -->
    <!-- wp_path_rel_to_home: http://original.mymultisi.te -->
    <!-- pos:  -->
    <!-- home_path a:  -->
    <!-- home_path b: /  -->

    Which completely explains the wrong home path...

  • RavanH

    Here is my patched and tested snapshot_utility_get_blog_upload_path():

    function snapshot_utility_get_blog_upload_path($switched_blog_id=0, $key='basedir') {
    	global $blog_id;
    	$home_path = get_home_path();
    
    	//echo "switched_blog_id[". $switched_blog_id ."] key[". $key ."]<br />";
    	if (is_multisite()) {
    		$blog_id_org = $blog_id;
    
    		switch_to_blog($switched_blog_id);
    		$uploads = wp_upload_dir();
    
    		if ($key == "basedir") {
    			if (isset($uploads['basedir'])) {
    				$upload_path = str_replace('\\', '/', $uploads['basedir']);
    				$upload_path = str_replace($home_path, '', $upload_path);
    			}
    		} else if ($key == "baseurl") {
    
    			if (isset($uploads['baseurl'])) {
    				$upload_path = array();
    				$upload_path['raw'] = str_replace('\\', '/', $uploads['baseurl']);
    
    				if ( (defined( 'UPLOADS' )) && (UPLOADS != '')) {
    					$UPLOADS = str_replace( '/'. $blog_id_org .'/', '/'. $switched_blog_id .'/', untrailingslashit(UPLOADS));
    					$upload_path['rewrite'] = str_replace( $UPLOADS, 'files', $upload_path['raw'] );
    					$upload_path['rewrite'] = str_replace(get_option('siteurl') .'/', '', $upload_path['rewrite']);
    				}
    				$upload_path['raw'] = str_replace(get_option('siteurl') .'/', '', $upload_path['raw']);
    			}
    		}
    		restore_current_blog();
    
    	} else {
    		$uploads = wp_upload_dir();
    		if ($key == "basedir") {
    			if (isset($uploads['basedir'])) {
    				$upload_path = str_replace('\\', '/', $uploads['basedir']);
    				$upload_path = str_replace($home_path, '', $upload_path);
    			}
    		} else if ($key == "baseurl") {
    			if (isset($uploads['baseurl'])) {
    				$upload_path = str_replace(get_site_url(), '', $uploads['baseurl']);
    			}
    		}
    	}
    
    	if ($key == "basedir") {
    		if (!$upload_path) {
    			$upload_path = trailingslashit(WP_CONTENT_DIR) . "uploads";
    			$upload_path = str_replace('\\', '/', $upload_path);
    			$upload_path = str_replace($home_path, '', $upload_path);
    		}
    	}
    
    	return $upload_path;
    }

    Manual and automated backups including files are working again! Wahoo! :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.