A PHP script that backs up the web server's HTML directories on ALL-INKL.COM (or elsewhere 😉). The script can be run with a KAS cron job. It is very suitable for people who only have an ALL-INKL account and do not have a remote server with SSH and crontab.
$NUM_BACKUPS
defines the maximum number of backups. The default value is 7
(for one week with a daily KAS cron job).<?php /** * Rotational PHP backup for ALL-INKL.COM * * Features: * Creates the following folder structure and rotates it: * current -> /path/to/backup/daily.0 * daily.0 * daily.1 * daily.2 * daily.3 * daily.4 * daily.5 * daily.6 * daily.7 * * Usage: * If the script is to be executed automatically via KAS cron job, it must be accessible on the web. * Alternatively, it can be run manually via shell with the following command: * "php /path/to/script.php" (pitfall wrong PHP CLI version, then e.g. "/usr/bin/php81 /path/to/script.php" for PHP 8.1 * See also: https:all-inkl.com/wichtig/anleitungen/kas/ssh/dateiverwaltung/aenderung-der-php-cli-version_527.html) * * Restore folder(s): * rsync -avz --progress /www/htdocs/v0xxxxx/backup/public_websites/daily.0/folder /www/htdocs/v0xxxxx/public_websites/folder/ * * @author Helmut Kaczmarek <email@helmutkaczmarek.de> * @link https://wiki.helmutkaczmarek.de/code:php:backup:rotation * @todo You could also back up the directories to a remote server via SSH. However, at this point one would probably no longer be dependent on the "trimmed" KAS cron jobs from ALL-INKL.com. A bash script and crontab would of course be the first choice in this case. */ // Configuration variables $SRC = "/www/htdocs/v0xxxxx/public_websites/"; $DEST = "/www/htdocs/v0xxxxx/backup/public_websites"; $NUM_BACKUPS = 7; // Creating the directories for ($i = 0; $i <= $NUM_BACKUPS; $i++) { mkdir($DEST . '/daily.' . $i, 0777, true); } // Delete the oldest backup system('rm -rf ' . $DEST . '/daily.' . $NUM_BACKUPS); // Rotation of backups for ($i = $NUM_BACKUPS - 1; $i >= 0; $i--) { $prev = $i + 1; system('mv ' . $DEST . '/daily.' . $i . ' ' . $DEST . '/daily.' . $prev); } // Creating the new backup system('rsync -arl --delete --stats --link-dest=' . $DEST . '/daily.1 ' . $SRC . ' ' . $DEST . '/daily.0'); // Symlink to the latest backup unlink($DEST . '/current'); symlink($DEST . '/daily.0', $DEST . '/current'); ?>