PHP script for backing up FTP data: How to set up the script
Step 1:
In order to make a backup of your FTP data, you can use the PEAR package Archive_Tar within a PHP script. This PEAR package is installed on our servers by default. Here you can see an example of use:1. Create a folder (e.g. "backup") inside your account.
2. Create a subfolder named "archive".
3. In the "backup" folder, please also create a PHP file named "ftp-backup.php" containing the following code:
<?
// Optimize PHP configuration
@error_reporting(E_ALL ^ E_WARNING);
@ini_set("max_execution_time", 300);
@ini_set("memory_limit", "256M");
// Subfolder to be backed up. Remains empty in case the entire account should be backed up.
$directory = "";
// Resources that must be excluded
$ignore = array("*.sql.gz", "*.tar.gz", "usage", "logs");
// Include PEAR class and create archive
include "Archive/Tar.php";
$archiv = new Archive_Tar("archiv/" . $_SERVER['USER'] . date('_Y-m-d_His') . ".tar.gz", true);
$archiv->setIgnoreList($ignore);
$archiv->createModify($_SERVER['HOME'] . "/" . $directory, "", $_SERVER['HOME']);
echo "Backup finished";
?>
4. In case of backing up only a single folder, please enter the path to that folder in the following variable:
$directory = "path/to/folder";
5. In order to execute the backup, call up the script in your web browser:
http(s)://your-domain.com/backup/ftp-backup.php
The script will be initiated and stores a backup file named KAS-Login_YYYY-MM.DD_TIME.tar.gz in the "archive" folder (/backup/archive).
Depending on the size of the data to be backed up, the process takes several minutes. We recommend data of a size of more than 5 GB to split into multiple backup files. This script can also be used for an automated backup process over night which you can realize with the help of a cronjob that can be set up inside your KAS (Technical Administration) panel. A weekly execution of the script is entirely sufficient. The backed up data can be regularly downloaded using an FTP client which is installed on your local computer.
Hint:
In order to prevent the script from being publicly accessible, please set up a directory protection for the "backup" folder. Afterwards, the script can only be reached by entering username and password. A tutorial can be found here.
Search in support and FAQ