A script to trigger a DB backup in Forge. Use this in deploy scripts to back up every time you deploy.
- A Laravel Forge account, with a valid API key
- A server with
jq
andcurl
installed (if you created the server through Forge recently, it probably has both installed already.)
Copy the contents of backup.sh to the deploy script section of Forge (also works in Envoyer, or theoretically any server...). The three required variables are the server ID, the backup ID, and your API key.
You may optionally increase or decrease the time before this script will timeout (default is 10 minutes). You can also uncomment the last two lines of the script if you want the deployment to fail on timeout.
You can find the server ID in the upper right corner the server home page.
After creating a DB backup in Forge, you can find its ID in parenthesis in the backup name.
The script initially gets the UUID of the most recent backup file before triggering a new backup job. Then it begins polling via API calls every 10 seconds to check the UUID of the latest backup file. Once the manually triggered job is finished, the latest file UUID will be different than the initial UUID and the loop exits. If there is no change in 10 minutes (or whatever you set the timeout value), the script prints an error and continues.