Sam's Website Backup V1.1
For osC V2.3.x and earlier
This contribution creates a zip file of your entire site (excluding the database) for immediate download to your computer so making creation of a site backup quick and easy with just a single click.
Compatibility:
Your backup, cached and sessions folders will be excluded, others can be easily added to that list.
Security:
The code will check the user is logged into admin at all stages, so only administrators are able to obtain and download the compressed site copy.
History:
This contribution concept was originally released as Backup All Store Files In Zip Format however there were a number of issues with that especially with memory usage. Very little code used in that remains, hence the re-badging.
Two zipping methods are provided, File and Memory (streaming) plus a GZipping option.
File Mode Zipping.
The file method first creates a temporary zipped copy of the website within your backup folder then immediately provides the download of that, the temporary zipped copy is then immediately deleted. This process uses very little memory so will always work as long as there is sufficient disk space to store the temporary file.
Memory Mode Zipping.
With this method the zipping all occurs within memory and at the same time the download is provided (streaming). Memory usage is still relatively low so should not prove an issue, however this requires at least PHP Version 5.1.2, if your server has less than that the memory mode zipping option will not appear.
Memory Mode GZipping.
Again GZipping all occurs within memory and once a tar package has been created (in memory). Once the whole file is created its presented for download. Memory usage is reasonable but the highest of all the options. This option is currently experimental and will fail for many as the tar parsing requires a re-write, if you use please report results.
Why the three different methods, they all have one issue or another, by providing choice you should always find at least one that works for you.
The Website Backup page will state how big the website is and how many files + folders will be backed up together with an estimate of how big the zipped file will be so you can tell if your likely to have sufficient space for a temporary file.
Works with osC 2.3.x and below, a template_top.php file is provided for anyone using this on osC 2.2 or lower.
Basic install is just 8 easy steps.
Support Forum at http://forums.oscommerce.com/topic/385393.
Download available at http://addons.oscommerce.com/info/8387.
Version Updates
V 1.1
- Added GZipping option to widen server compatibility.
- Added test for existence of ZipArchive class.
- Modified headers to widen compatibility.
- Added additional testing for configuration variables.
- Added inclusion of zero byte files in backup files.
- Added inclusion of empty directories in backup files.
- Removed Content Length on streaming (for now) as it seems to cause issues.
- Added session check controls, see settings.
- Moved functions to separate file.
Changed files: backup_website.php, admin/includes/classes/zipstream.php, languages/english/backup_website.php
Added files: /admin/includes/functions/backup_site_functions.php, admin/includes/classes/tar.class.php
Settings
The only settings are within the admin->backup_website.php file at the top.
$exclude = 'DIR_FS_BACKUP, DIR_FS_CACHE, SESSION_WRITE_DIRECTORY'; Just add any folders to be excluded as required, include the full path from catalog folder i.e. includes/languages/.
ini_set('memory_limit', '512M'); Sets memory limit, increase if you receive an out of memory error, though very unlikely.
$guess = 0; An estimate is made of the download size, this must be larger than the actual or you will find your zipped file is corrupt after download, if this occurs just increase the guess value by single digits, i.e. a 1 will mean a 1% size increase. However please be aware if the over estimate is too big that can also cause issues.
error_reporting(0); All error messages disabled, as any will cause download failure, comment out if you have any problems.
$no_session = false; Set to true if you don't use sessions for admin login. WARNING doing this creates a security risk.
$session_name = 'admin'; Alter if you've changed the admin session name (NOT just renamed the admin folder)
Notes
Website Size Your website size after ignoring any excluded folders will be shown together with an estimate of backup size. If you add any folders to be excluded check this figure (and the folder/file count) drops, otherwise check your entries and your admin/configure.php file. If any folders to be excluded don't exist they will be listed as such.
Empty (zero byte) files are recreated in file mode & duplicated in the others.
Empty Folders are more problematic, even where a class has a 'Add Empty Folder' option, if that folder remains empty it will not be created. The solution is to add an empty htaccess file to any empty folders, such a file will have no effect and will not alter any htaccess rules you have in place.
File & Folder Count. This may vary from your own for a number of reasons, this will include any hidden files & folders but will exclude any symbolic links, your own counter will likely have different rules.
If you have a large site note that some modes may need double your website size (after exclusions applied) of memory available.
Installation
Please read through all the instructions first & make sure you understand them, for safety you should always backup your site before making any changes.
1.- Copy backup_website.php to /admin/
2.- Copy zipstream.php to /admin/includes/classes/
3.- Copy tar.class.php to admin/includes/classes/
4.- Copy backup_site_functions.php to admin/includes/functions/
5.- Copy backup_website.php to /admin/includes/languages/english
6.- Open admin/includes/filenames.php
Add before the final ?>
7.- Open admin/includes/languages/english.php
Add before the final ?>
8a.- osC 2.3.x: Open admin/includes/boxes/tools.php
Find:
Add after:
8b.- osC 2.2 or lower: Open admin/includes/boxes/tools.php
Find:
Add after:
9.- Upload all changed files and new files to your site.
Upgrading
Just replace the old files with those in this package and add the new.
Requires any osC upto 2.3.x and is register_globals off compatible.
A lot of effort has been made to create this project, if you are using the code within a commercial site a donation would be gratefully received and would help to ensure continued development.