Goal
To have one more more environments automatically backed up through snapshots triggered without manual intervention.
Assumptions
- Access to a project hosted on Platform.sh
- Your project account has administrator rights
- Knowledge on using the project web interface or the Platform.sh CLI
- CLI tool set up in the environment, as described in this how-to
Problems
The snapshot process is not automated and requires a manual trigger using the CLI or web interface.
Steps
1. Check the CLI tool is correctly installed in the environment
After logging in with SSH in the environment, you should be able to run platform
and see the welcome prompt, together with a list of your projects.
2. Add a cron for automated environment snapshots
Edit your .platform.app.yaml
file and add the snapshot command in a cron. Example:
crons:
auto_snapshot:
# The cron task will run everyday at 4 am (UTC)
spec: '0 4 * * *'
cmd: |
if [ "$PLATFORM_ENVIRONMENT_TYPE" = "production" ]; then
platform backup:create --yes --no-wait
fi
The PLATFORM_BRANCH
variable check ensures automatic snapshots are done only on the production environment. The --yes
flag skips user interaction for the snapshot command. Ensure the --no-wait
parameter is added to the command, in order to make the operation non-blocking (otherwise, your site will be down until the snapshot operation is completed).
Conclusion
After setting up the CLI tool in the environment, we learned how to use it in order to trigger various maintenance tasks for the project.