RSS
 

Restoring previous versions of files in Dropbox

05 Jun

One of the most common questions I am asked now the WordPress Backup to Dropbox 0.8 has been released is, now that the zipping has been removed, can one still get an earlier version of a file that has been backed up? The answer to this question is, yes you can! Dropbox has this functionality built in and it is extremely easy to do.

Lets just say you botched a post and want to revert to a database a few days old. To do so go to the Dropbox web interface and navigate to the file that you wish to revert.

Once you have located the file all you need to do is click the little down arrow on the right hand side and select ‘Previous Versions’.

Note: You can also select ‘Previous Versions’ within the Dropbox folder on your computer by right clicking on the file and selecting this option in the Dropbox sub menu.

Once selected you will be presented Dropbox’s Previous versions page.

As you can see I dump my WordPress database every day so I can revert my SQL dump to any version within the last 30 days by selecting the day that I wish to revert to and clicking the restore button.

More information can be found in the Dropbox help page.

 
Comments Off

Posted in Uncategorized

 

WordPress Backup to Dropbox 0.8

26 May

After many late nights I am pleased to finally release WordPress Backup to Dropbox 0.8!

In this release I have significantly changed the way backups are performed in order to make the process more efficient, smarter and use less memory and bandwidth. The biggest problems that people have been reporting is the plugin “Does not work” or “Starts but no backup is appearing in Dropbox”. Firstly, let me assure you, that I tested the original version on few WordPress installations and all seemed fine, unfortunately, my sample size was too small and others have run into problems.

I managed to identify three major issues that contributed to failing backups.

Issue 1: Memory

Zipping large files in PHP can be quite memory intensive and the method I originally used read an entire file into memory before compressing it and adding it to the archive. So if your website contained a file that was approximately 50% the size of your PHP memory limit setting then the process would raise a fatal error. In version 0.7.2 I added a quick hack that increases this limit via the ini_set() function. Unfortunately modifying this setting is blocked when PHP is running in safe mode or the Suhosin Patch has been applied. The former of which is very common on shared hosts around the world.

The same issue applies when uploading a file to Dropbox which is bad considering that a websites archive can easily be quite large!

In this new version I have removed zipping altogether in favor of a smarter differential backup algorithm. Each file will now be uploaded individually if does not exist in Dropbox, or has changed on your sever since the last backup.  Of course, this will mean that your initial backup will be larger then that of a zipped archive, however all subsequent backups will only contain files that have changed thus decreasing bandwidth.

In addition I have added a warning system where, instead of failing, the algorithm will log a warning if an upload of a file fails. Currently a warning is raised if it encounters a file that will exceed the memory limit setting in PHP, the upload times out or there is an error connecting to the Dropbox server.

Issue 2: Safe Mode

A backup can take a very long time to complete so the plugin needs to set PHP’s max execution time to unlimited to get the job done. If your server has PHP compiled with safe mode enabled then there is no way this can be set in code. For more information please read the blog post I wrote about this problem.

If you are in this situation the plugin will now warn you that you need to manually set you max execution time to a larger value and  attempt to backup your WordPress installation. If the backup duration nears this setting then the backup will fail alerting you to the fact that it is has been set too low.

Issue 3: Your Host

The third major issue I encountered is the fact that some hosts, including my own, kill long running processes. So regardless of the setting you have set above if the process takes longer then the host allows it will be killed. To get around this I have introduced cron job to the plugin that will monitor the backup process to ensure it is still running. If the monitor notices that no activity has occurred in five minutes then a new backup process will be started resuming from where the last one failed.

Conclusion

In addition to these major fixes I have added validation of the paths and fixed a couple smaller issues to increase the stability of the plugin.

I hope this version will work for all, however there is no such thing as bug free code! So if you have any issues, rather then just giving the plugin a low rating or tagging it as broken, please let me know and I will endeavor to fix them.

Issues can be raised in the BitBucket issue tracker or the WordPress forum for my plugin.

 

Setting the maximum execution time when PHP is running in safe mode

24 May

Many php applications, like WordPress Backup to Dropbox, require an extended max execution time PHP setting in order to complete a task. By default this setting is set to 30 seconds and, in the case of my WordPress plugin, is not enough for a backup to be completed.

If the PHP installation was not compiled in safe mode then we can change this value within the application using set_time_limit. So for any long running scripts setting the time limit to zero will tell PHP to allow the script to run forever.

However if your PHP installation is running in safe mode, this function is blocked and there is no way of altering the time limit from within the application. Therefore the only way to get the an application to complete its task the php.ini max_execution_time setting will need to be altered. In the case of WordPress Backup to Dropbox this setting needs to be set to at least 3600 seconds  (1 hour).

How easily this value can be changes depends on how your hosts PHP installation is configured. If your host allows it you can put a file named php.ini inside the root of your WordPress installation with the max_execution_time set.

max_execution_time = 0

If this does not work then you have to edit the value in your php.ini file. The location of this file depends on your operating system and a quick Google search will yield plenty of literature on how this is done.