Website Backups with Cronjobs
Since Kirby uses plaintext files, it's straightforward to back up entire sites via cronjob. The zipped archives stay on the same server, which is not ideal — consider dedicated tools like rsnapshot or borg backup for deduplicated off-server backups.
Source: yeahhub.com — Simple Backup Script Cronjob
Setup steps
- Create a
site_backupsfolder in the home directory on cyonmkdir site_backups - Create the backup script at
/sitebackups/sitebackups.sh - Test the commands manually first
- Create the cronjob at the hosting provider
The backup script
Adapt CLIENT_FOLDER and PROJECT_FOLDER to match the hosting account and site URL.
#!/bin/bash
DATE=$(date +%d-%m-%Y)
# Back up each website into a dated archive
tar -zcvpf /home/CLIENT_FOLDER/site_backups/backup-dev-PROJECT_FOLDER-de-$DATE.tar.gz \
/home/CLIENT_FOLDER/public_html/dev.PROJECT_FOLDER.de
tar -zcvpf /home/CLIENT_FOLDER/site_backups/backup-PROJECT_FOLDER-de-$DATE.tar.gz \
/home/CLIENT_FOLDER/public_html/PROJECT_FOLDER.de
# Delete backups older than 10 days
find /home/CLIENT_FOLDER/backup-* -mtime +10 -exec rm {} \;
Cronjob setup
Example cron entry — runs daily at 4:00 AM:
0 4 * * * /usr/bin/bash /home/CLIENT_FOLDER/sitebackups/sitebackups.sh
On cyon, cronjobs are managed via my.cyon under "Erweitert" → "Cronjobs". Reference: cyon.ch — Cronjob erstellen
Cron schedule format
Minute Stunde Tag Monat Wochentag
0 23 * * 7 → Sundays at 23:00
0 4 * * * → Daily at 04:00
Use crontab.guru to build and verify cron expressions.
Interpreter prefixes
- Bash scripts:
/usr/bin/bash /path/to/script.sh - PHP scripts:
/usr/bin/php /path/to/script.php
Schedule resource-intensive backups at off-peak hours. Make sure old backups are cleaned up automatically to avoid filling disk space.