mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-09 03:04:54 -04:00
docs: Add n8n backup automation example guide (#3648)
Co-authored-by: boc-the-git <3479092+boc-the-git@users.noreply.github.com>
This commit is contained in:
parent
01b9987812
commit
b3241d3e8b
BIN
docs/docs/assets/img/n8n/n8n-cred-app.png
Normal file
BIN
docs/docs/assets/img/n8n/n8n-cred-app.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
BIN
docs/docs/assets/img/n8n/n8n-cred-connection.png
Normal file
BIN
docs/docs/assets/img/n8n/n8n-cred-connection.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
BIN
docs/docs/assets/img/n8n/n8n-mealie-backup.png
Normal file
BIN
docs/docs/assets/img/n8n/n8n-mealie-backup.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 105 KiB |
BIN
docs/docs/assets/img/n8n/n8n-workflow-auth.png
Normal file
BIN
docs/docs/assets/img/n8n/n8n-workflow-auth.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
BIN
docs/docs/assets/img/n8n/n8n-workflow-import.png
Normal file
BIN
docs/docs/assets/img/n8n/n8n-workflow-import.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
386
docs/docs/assets/other/n8n/n8n-mealie-backup.json
Normal file
386
docs/docs/assets/other/n8n/n8n-mealie-backup.json
Normal file
@ -0,0 +1,386 @@
|
||||
{
|
||||
"name": "Mealie Backup",
|
||||
"nodes": [
|
||||
{
|
||||
"parameters": {
|
||||
"rule": {
|
||||
"interval": [
|
||||
{}
|
||||
]
|
||||
}
|
||||
},
|
||||
"id": "2ec440b4-0668-4bc0-aa66-4023d6379f28",
|
||||
"name": "Schedule Trigger",
|
||||
"type": "n8n-nodes-base.scheduleTrigger",
|
||||
"typeVersion": 1.1,
|
||||
"position": [
|
||||
240,
|
||||
660
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"method": "POST",
|
||||
"url": "https://mealie.example/api/admin/backups",
|
||||
"authentication": "genericCredentialType",
|
||||
"genericAuthType": "httpHeaderAuth",
|
||||
"options": {}
|
||||
},
|
||||
"id": "235f26f7-0f45-479e-a7e3-bf8cda7c8426",
|
||||
"name": "Run Backup ",
|
||||
"type": "n8n-nodes-base.httpRequest",
|
||||
"typeVersion": 4.1,
|
||||
"position": [
|
||||
520,
|
||||
520
|
||||
],
|
||||
"notesInFlow": false,
|
||||
"credentials": {
|
||||
"httpHeaderAuth": {
|
||||
"id": "GSL12tNi3MPvTZux",
|
||||
"name": "Mealie API"
|
||||
}
|
||||
},
|
||||
"notes": "Send an API call to run the backup"
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"method": "POST",
|
||||
"url": "https://ntfy.example/backups",
|
||||
"sendHeaders": true,
|
||||
"headerParameters": {
|
||||
"parameters": [
|
||||
{
|
||||
"name": "Title",
|
||||
"value": "Meale Backup Failure"
|
||||
},
|
||||
{
|
||||
"name": "Priority",
|
||||
"value": "urgent"
|
||||
},
|
||||
{
|
||||
"name": "Tags",
|
||||
"value": "warning"
|
||||
},
|
||||
{
|
||||
"name": "Actions",
|
||||
"value": "view, Open Mealie, https://mealie.example/admin/backups; view, Open n8n, https://n8n.example"
|
||||
}
|
||||
]
|
||||
},
|
||||
"sendBody": true,
|
||||
"contentType": "raw",
|
||||
"body": "\"Full Panic!\"",
|
||||
"options": {}
|
||||
},
|
||||
"id": "40ba81a5-5741-4b15-98af-1a9e6b34f997",
|
||||
"name": "Ntfy Warning",
|
||||
"type": "n8n-nodes-base.httpRequest",
|
||||
"typeVersion": 4.1,
|
||||
"position": [
|
||||
1000,
|
||||
520
|
||||
],
|
||||
"onError": "continueRegularOutput"
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"url": "https://mealie.example/api/admin/backups",
|
||||
"authentication": "genericCredentialType",
|
||||
"genericAuthType": "httpHeaderAuth",
|
||||
"options": {}
|
||||
},
|
||||
"id": "b75571d0-d926-440c-897f-55b89c6a5080",
|
||||
"name": "Get all backups",
|
||||
"type": "n8n-nodes-base.httpRequest",
|
||||
"typeVersion": 4.1,
|
||||
"position": [
|
||||
520,
|
||||
820
|
||||
],
|
||||
"credentials": {
|
||||
"httpHeaderAuth": {
|
||||
"id": "GSL12tNi3MPvTZux",
|
||||
"name": "Mealie API"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"fieldToSplitOut": "imports",
|
||||
"options": {}
|
||||
},
|
||||
"id": "943d0e83-682b-4500-9faf-53284cfb02c6",
|
||||
"name": "Split Out",
|
||||
"type": "n8n-nodes-base.splitOut",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
720,
|
||||
820
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"jsCode": "// Get input data\nconst inputData = items.map(item => item.json);\n\n// Sort the data based on the 'date' field in descending order\ninputData.sort((a, b) => new Date(b.date) - new Date(a.date));\n\n// Get all records except the latest 7\nconst allExceptLatest7 = inputData.slice(7);\n\n// Map the output data back to the required format\nreturn allExceptLatest7.map(record => ({ json: record }));\n"
|
||||
},
|
||||
"id": "64eae81d-fdb6-44f7-9a2d-eff8d1763281",
|
||||
"name": "Code",
|
||||
"type": "n8n-nodes-base.code",
|
||||
"typeVersion": 2,
|
||||
"position": [
|
||||
860,
|
||||
820
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"method": "DELETE",
|
||||
"url": "=https://mealie.example/api/admin/backups/{{ $json.name }}",
|
||||
"authentication": "genericCredentialType",
|
||||
"genericAuthType": "httpHeaderAuth",
|
||||
"options": {}
|
||||
},
|
||||
"id": "1148eeb8-4860-46df-8f61-0e85ea1e0e89",
|
||||
"name": "Delete Oldies",
|
||||
"type": "n8n-nodes-base.httpRequest",
|
||||
"typeVersion": 4.1,
|
||||
"position": [
|
||||
1040,
|
||||
820
|
||||
],
|
||||
"credentials": {
|
||||
"httpHeaderAuth": {
|
||||
"id": "GSL12tNi3MPvTZux",
|
||||
"name": "Mealie API"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"content": "Sends API Call to run backup",
|
||||
"height": 225,
|
||||
"width": 226,
|
||||
"color": 4
|
||||
},
|
||||
"id": "cd2cb5db-87c1-40d8-a746-e61ace231987",
|
||||
"name": "Sticky Note",
|
||||
"type": "n8n-nodes-base.stickyNote",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
460,
|
||||
460
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"content": "Is there an error?",
|
||||
"height": 225,
|
||||
"width": 231,
|
||||
"color": 3
|
||||
},
|
||||
"id": "0bebecbe-903e-4a69-bb1a-35619e68b540",
|
||||
"name": "Sticky Note1",
|
||||
"type": "n8n-nodes-base.stickyNote",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
700,
|
||||
460
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"content": "Send alert to NTFY",
|
||||
"height": 225,
|
||||
"width": 229
|
||||
},
|
||||
"id": "0b732adb-8a84-456d-b26d-5fc5ee5a4cae",
|
||||
"name": "Sticky Note2",
|
||||
"type": "n8n-nodes-base.stickyNote",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
940,
|
||||
460
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"content": "Gets all backups in Mealie",
|
||||
"height": 225,
|
||||
"width": 226,
|
||||
"color": 4
|
||||
},
|
||||
"id": "99c6886b-6a07-4b51-b395-d4bbcbde7d18",
|
||||
"name": "Sticky Note3",
|
||||
"type": "n8n-nodes-base.stickyNote",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
460,
|
||||
760
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"content": "Splits the data, and parses the output",
|
||||
"height": 225,
|
||||
"width": 281
|
||||
},
|
||||
"id": "549555f8-0aed-42c0-9693-9c0d93902796",
|
||||
"name": "Sticky Note4",
|
||||
"type": "n8n-nodes-base.stickyNote",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
700,
|
||||
760
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"content": "Deletes all but the last 7 backups",
|
||||
"height": 225,
|
||||
"width": 229
|
||||
},
|
||||
"id": "bcc5f0ba-73e9-42d7-b01b-c32f9f69f2f7",
|
||||
"name": "Sticky Note5",
|
||||
"type": "n8n-nodes-base.stickyNote",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1000,
|
||||
760
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"content": "Run every day a 01:00",
|
||||
"height": 225,
|
||||
"width": 226,
|
||||
"color": 4
|
||||
},
|
||||
"id": "ce797062-d727-43e3-a27f-e29b13ad3c9a",
|
||||
"name": "Sticky Note6",
|
||||
"type": "n8n-nodes-base.stickyNote",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
180,
|
||||
600
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"conditions": {
|
||||
"options": {
|
||||
"caseSensitive": true,
|
||||
"leftValue": "",
|
||||
"typeValidation": "strict"
|
||||
},
|
||||
"conditions": [
|
||||
{
|
||||
"id": "8b00bb85-827f-4f2f-813e-db0d25e927d3",
|
||||
"leftValue": "={{ $json.error }}",
|
||||
"rightValue": "",
|
||||
"operator": {
|
||||
"type": "boolean",
|
||||
"operation": "true",
|
||||
"singleValue": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"combinator": "and"
|
||||
},
|
||||
"options": {}
|
||||
},
|
||||
"id": "fefd3e8b-9b71-490a-82e3-25e5468a4135",
|
||||
"name": "Error?",
|
||||
"type": "n8n-nodes-base.filter",
|
||||
"typeVersion": 2,
|
||||
"position": [
|
||||
760,
|
||||
520
|
||||
]
|
||||
}
|
||||
],
|
||||
"pinData": {},
|
||||
"connections": {
|
||||
"Schedule Trigger": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Run Backup ",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"node": "Get all backups",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Run Backup ": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Error?",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Get all backups": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Split Out",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Split Out": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Code",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Code": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Delete Oldies",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Error?": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Ntfy Warning",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
"active": false,
|
||||
"settings": {
|
||||
"executionOrder": "v1"
|
||||
},
|
||||
"versionId": "68e3e469-3ddb-4838-b09d-3c69fdd851f5",
|
||||
"meta": {
|
||||
"templateCredsSetupCompleted": true,
|
||||
"instanceId": "630eefaa8c490b9c5221d83a182af6450c2c3efaf4b580b8ac348631abfe1aeb"
|
||||
},
|
||||
"id": "whloxeXkdBWWi2Uj",
|
||||
"tags": []
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
# Automating Backups with n8n
|
||||
|
||||
!!! info
|
||||
This guide was submitted by a community member. Find something wrong? Submit a PR to get it fixed!
|
||||
|
||||
> [n8n](https://github.com/n8n-io/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:
|
||||
|
||||
1. Backups Mealie every morning via an API call
|
||||
2. 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](https://docs.n8n.io/)
|
||||
|
||||
## Importing n8n workflow
|
||||
|
||||
1. In n8n, add a new workflow
|
||||
2. In the top right hit the 3 dot menu and select 'Import from URL...'
|
||||
|
||||

|
||||
|
||||
3. Paste `https://github.com/mealie-recipes/mealie/blob/mealie-next/docs/docs/assets/other/n8n/n8n-mealie-backup.json` and click Import
|
||||
4. Click through the nodes and update the URLs for your environment
|
||||
|
||||
## API Credentials
|
||||
|
||||
#### Generate Mealie API Token
|
||||
|
||||
1. 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
|
||||
2. Under token name, enter the name of the token i.e. 'n8n' and hit Generate
|
||||
3. 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
|
||||
|
||||
> [n8n Docs](https://docs.n8n.io/credentials/add-edit-credentials/)
|
||||
|
||||
1. Create a new "Header Auth" Credential
|
||||
|
||||

|
||||
|
||||
2. In the connection screen set - Name as `Authorization` - Value as `Bearer {INSERT MEALIE API KEY}`
|
||||
|
||||

|
||||
|
||||
3. 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](https://github.com/binwiederhier/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](https:/pushover.net/) you could create a new node that uses the Pushover API and sends the notification.
|
||||
- You can use the [Send Email](https://docs.n8n.io/integrations/builtincore-nodes/n8n-nodes-base.sendemail/) 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](https://discord.gg/QuStdQGSGK) and say hi!
|
@ -79,8 +79,8 @@ nav:
|
||||
- Permissions and Public Access: "documentation/getting-started/usage/permissions-and-public-access.md"
|
||||
|
||||
- Authentication:
|
||||
- LDAP: "documentation/getting-started/authentication/ldap.md"
|
||||
- OpenID Connect: "documentation/getting-started/authentication/oidc.md"
|
||||
- LDAP: "documentation/getting-started/authentication/ldap.md"
|
||||
- OpenID Connect: "documentation/getting-started/authentication/oidc.md"
|
||||
|
||||
- Community Guides:
|
||||
- iOS Shortcuts: "documentation/community-guide/ios.md"
|
||||
@ -88,6 +88,7 @@ nav:
|
||||
- Home Assistant: "documentation/community-guide/home-assistant.md"
|
||||
- Bulk Url Import: "documentation/community-guide/bulk-url-import.md"
|
||||
- Import Bookmarklet: "documentation/community-guide/import-recipe-bookmarklet.md"
|
||||
- Automate Backups with n8n: "documentation/community-guide/n8n-backup-automation.md"
|
||||
|
||||
- API Reference: "api/redoc.md"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user