If you’ve ever worked with a large website and wanted to download a copy of it, FTP could drive you nuts (especially if you have a flaky internet connection). You probably assumed there is some way to zip (archive) a site into one large file for easy download. Now even if you don’t have shell access to your web server you can create a single file for download.
All of the steps below are assuming that you are running a Linux/Unix system with Apache and PHP installed. If your on IIS / Windows this may or may not work. You’ll also need to know the root path of your server, our demo will be set to /home/demouser/demodomain.com/
First off you need to make sure that the web site you want to back-up is not running in Safe Mode. If the site is, request from your hosting provider that it be turned off. Safe Mode doesn’t allow for system commands to be run.
Next you’d want to create a folder that has write permissions (chmod 0777) to place your archive into. We’ll call this folder “backup” for demo purposes.
Now comes the actual code to back-up your website folder.
<?php
system(“tar -zcf /home/demouser/demodomain.com/backup/mybackup.tar.gz /home/demouser/demodomain.com”);
?>
Don’t worry I’ll explain what this all means.
system
This command basically will replicate a shell prompt for you, however you can only run one command at a time (without some fancy coding)
tar
This is the code to create the actual archive file, on Linux/Unix they call it a “tarball” or “tar”
-zcf
this is creating a compressed tar file (z) means zip or .gz format (c) is create command (f) means file.
/home/demouser/demodomain.com/backup/mybackup.tar.gz
This is the file path that you want to create. You can name backup and mybackup.tar.gz whatever you’d like.
/home/demouser/demodomain.com
This is telling the system what folder on the system to backup. Depending on the size of your site you may see the page sit for a few seconds. When the page is done you can point your browser to www.demodomain.com/backup/mybackup.tar.gz and download your file.
Hope that helps those of you with large backup issues. Also this can be run from a cronjob to create regular backups that your clients can easily download.
~RDS




