-
Notifications
You must be signed in to change notification settings - Fork 4
Automatic version creation
Lukas Bestle edited this page Oct 2, 2021
·
1 revision
The Versions plugin is primarily suited for manual version creation whenever there is a meaningful set of changes. You can however also automatically create versions as an automatic backup in case the editors forget to create versions themselves.
Versions can be created with a simple script like this:
#!/bin/bash
# ▼──── customize the following four lines
authorName="Automatic snapshot"
authorEmail="snapshot@example.com"
message="Automatic snapshot at $(date "+%Y-%m-%d %H:%M:%S")"
cd /var/www/your-site/content
# ▲────
# check if there are any Kirby lock files
if ls .lock &> /dev/null || ls **/.lock &> /dev/null; then
echo "Found Kirby .lock files, no automatic snapshot created"
exit 0
fi
git add -A
git -c "user.name=$authorName" -c "user.email=$authorEmail" commit -m "$message" || exit 0
commit="$(git rev-parse --short HEAD)"
git -c "user.name=$authorName" -c "user.email=$authorEmail" tag "$(date +%Y%m%d_snapshot_$commit)" -am "$message"
You can run the script from a cronjob, for example daily at night. Ensure that the git
binary is available in cron
's $PATH
.
Versions created with the commands from the example script above will automatically be picked up by the Versions plugin just like versions created from the Versions interface.