*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* 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
*
* Restore folder(s):
* rsync -avz --progress /backup/folder/ /folder/to/be/restored
*
* @author Helmut Kaczmarek
* @link https://www.helmutkaczmarek.de
* @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');
?>