Automating Backups with n8n
Info
This guide was submitted by a community member. Find something wrong? Submit a PR to get it fixed!
n8n is a free and source-available fair-code licensed workflow automation tool. Alternative to Zapier or Make, allowing you to use a UI to create automated workflows.
This example workflow:
- Backups Mealie every morning via an API call
- Deletes all but the last 7 backups
[!CAUTION] This only automates the backup function, this does not backup your data to anywhere except your local instance. Please make sure you are backing up your data to an external source.
Setup
Deploying n8n
Follow the relevant guide in the n8n Documentation
Importing n8n workflow
- In n8n, add a new workflow
- In the top right hit the 3 dot menu and select 'Import from URL...'
- Paste
https://github.com/mealie-recipes/mealie/blob/mealie-next/docs/docs/assets/other/n8n/n8n-mealie-backup.json
and click Import - Click through the nodes and update the URLs for your environment
API Credentials
Generate Mealie API Token
- Head to https://mealie.example.com/user/profile/api-tokens
If you dont see this screen make sure that "Show advanced features" is checked under https://mealie.example.com/user/profile/edit
- Under token name, enter the name of the token i.e. 'n8n' and hit Generate
- Copy and keep this API Token somewhere safe, this is like your password!
You can use your normal user for this, but assuming you're an admin you could also choose to create a user named n8n and generate the API key against that user.
Setup Credentials in n8n
- Create a new "Header Auth" Credential
- In the connection screen set - Name as
Authorization
- Value asBearer {INSERT MEALIE API KEY}
- In the workflow you created, for the "Run Backup", "Get All backups", and "Delete Oldies" nodes, update:
- Authentication to
Generic Credential Type
- Generic Auth Type to
Header Auth
- Header Auth to
Mealie API
or whatever you named your credentials
Notification Node
Please use error notifications of some kind. It's very easy to set and forget an automation, then have the worst happen and lose data.
ntfy is a great open source, self-hostable tool for sending notifications.
If you want to use ntfy, you will need to install it on your environment, or sign up for their service, and configure it with the webhook URL.
If you want to use another notification service, you can create a new node in n8n that sends the notification using whatever method you like.
- For example, if you want to send a push notification via Pushover you could create a new node that uses the Pushover API and sends the notification.
- You can use the Send Email node in n8n as an example of how to create your own custom node.
- You can send it off to InfluxDB, Slack, Discord etc. Go nuts.
If you're using another method for backups we'd love to hear about it. Pop in Discord and say hi!