{ "name": "Paperless Sync: 192.168.2.155 docker-prod", "nodes": [ { "parameters": {}, "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [ -208, 0 ], "id": "d083c73f-dac8-423e-ab66-8d8f406b520c", "name": "When clicking ‘Execute workflow’" }, { "parameters": { "url": "https://192.168.2.155:9443/api/stacks", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Content-Type", "value": "application/json" } ] }, "options": { "allowUnauthorizedCerts": true } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.3, "position": [ 240, 0 ], "id": "27e57a61-7822-4a1d-ba9b-9540946dcecc", "name": "get stack list", "credentials": { "httpHeaderAuth": { "id": "O8YTyppi2WklkirZ", "name": "portainer-api 192.168.2.155" } } }, { "parameters": { "method": "POST", "url": "=https://192.168.2.155:9443/api/stacks/{{$json.stackId}}/stop?endpointId={{$json.endpointId}}\n", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "allowUnauthorizedCerts": true } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.3, "position": [ 688, 0 ], "id": "7c2da8c8-5a5f-497d-8165-4c8f2b1d1a0d", "name": "stop stack", "credentials": { "httpBasicAuth": { "id": "iJkXePPAceSyENTx", "name": "CMI CAN Bus local" }, "httpHeaderAuth": { "id": "O8YTyppi2WklkirZ", "name": "portainer-api 192.168.2.155" } } }, { "parameters": { "amount": 10 }, "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ 912, 0 ], "id": "3a6756eb-c25b-41ee-9b01-f3e96a518ba0", "name": "wait 10 secs", "webhookId": "e103fb01-a525-421d-89c4-a3316598f945" }, { "parameters": { "method": "POST", "url": "=https://192.168.2.155:9443/api/stacks/{{ $('select stack by name').item.json.stackId }}/start?endpointId={{ $('select stack by name').item.json.endpointId }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "allowUnauthorizedCerts": true } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.3, "position": [ 688, 224 ], "id": "c5f8be8a-3f5b-4c7f-aa36-07bf03c00a0d", "name": "start stack", "executeOnce": true, "credentials": { "httpBasicAuth": { "id": "iJkXePPAceSyENTx", "name": "CMI CAN Bus local" }, "httpHeaderAuth": { "id": "O8YTyppi2WklkirZ", "name": "portainer-api 192.168.2.155" } }, "onError": "continueRegularOutput" }, { "parameters": { "url": "https://192.168.2.155:9443/api/endpoints/2/docker/containers/json?all=1", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "allowUnauthorizedCerts": true } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.3, "position": [ 912, 224 ], "id": "0bf1c970-01be-4f3b-9a5b-44864a900434", "name": "list containers", "credentials": { "httpHeaderAuth": { "id": "O8YTyppi2WklkirZ", "name": "portainer-api 192.168.2.155" } } }, { "parameters": { "assignments": { "assignments": [ { "id": "dfe53d42-71aa-4bbd-9cc1-90228d46ba6c", "name": "stackName", "value": "paperless-ngx", "type": "string" }, { "id": "b350e0c4-751a-4b8f-a8fd-29cae43f3953", "name": "endpointId", "value": 2, "type": "number" }, { "id": "bae42f62-9ca5-48ac-ba32-3b9fff0df26a", "name": "confirmWipe", "value": "YES_I_KNOW_THIS_DELETES_DATA", "type": "string" } ] }, "options": {} }, "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 16, 0 ], "id": "21235d87-b4eb-4f4a-bcd7-05b5cc329fa7", "name": "stack config" }, { "parameters": { "jsCode": "const targetName = $('stack config').item.json.stackName; // paperless-ngx\nconst endpointIdWanted = $('stack config').item.json.endpointId; // 3\n\n// get stack list liefert mehrere items (je stack ein item)\nconst stacks = $input.all().map(i => i.json);\n\nconst match = stacks.find(s =>\n s.Name === targetName && Number(s.EndpointId) === Number(endpointIdWanted)\n);\n\nif (!match) {\n throw new Error(`Stack '${targetName}' (endpoint ${endpointIdWanted}) nicht gefunden`);\n}\n\nreturn [{\n json: {\n ...$('stack config').item.json,\n stackId: match.Id,\n endpointId: match.EndpointId,\n stackType: match.Type,\n projectPath: match.ProjectPath,\n entryPoint: match.EntryPoint,\n }\n}];\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 464, 0 ], "id": "1089ea6b-0e76-4679-8d9e-4e0a59db27ed", "name": "select stack by name" }, { "parameters": { "url": "={{ 'https://192.168.2.155:9443/api/endpoints/' + $json.EndpointId + '/docker/volumes' }}\n\n\n\n", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "allowUnauthorizedCerts": true } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.3, "position": [ 1136, 0 ], "id": "94535e12-d598-4cb3-aa9a-87a1e02f7833", "name": "list volumes", "credentials": { "httpHeaderAuth": { "id": "O8YTyppi2WklkirZ", "name": "portainer-api 192.168.2.155" } } }, { "parameters": { "jsCode": "const stackCfg = $items('stack config')[0].json;\n\nconst stackName = stackCfg.stackName; // paperless-ngx\nconst confirm = stackCfg.confirmWipe; // YES_I_KNOW_THIS_DELETES_DATA\n\n\nif (confirm !== 'YES_I_KNOW_THIS_DELETES_DATA') {\n throw new Error('confirmWipe fehlt oder falsch. Abbruch (Sicherheitsgurt).');\n}\n\nconst volumes = $input.first().json.Volumes || [];\nconst filtered = volumes.filter(v => {\n const name = v.Name || '';\n const labels = v.Labels || {};\n // Sicherster Weg: compose project label\n const project = labels['com.docker.compose.project'];\n return project === stackName || name.startsWith(`${stackName}_`);\n});\n\nreturn filtered.map(v => ({\n json: {\n volumeName: v.Name,\n volumeNameEncoded: encodeURIComponent(v.Name),\n mountpoint: v.Mountpoint || null\n }\n}));\n\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1360, 0 ], "id": "6463d4ef-5651-4add-b496-f5435462d449", "name": "filter paperless volumes" }, { "parameters": { "method": "DELETE", "url": "=https://192.168.2.155:9443/api/endpoints/{{$items('stack config')[0].json.endpointId}}/docker/volumes/{{$json.volumeNameEncoded}}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "allowUnauthorizedCerts": true } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.3, "position": [ -208, 224 ], "id": "373c6589-8a0e-4917-b6c7-f43a681e1e23", "name": "delete volume", "alwaysOutputData": true, "credentials": { "httpHeaderAuth": { "id": "O8YTyppi2WklkirZ", "name": "portainer-api 192.168.2.155" } }, "onError": "continueRegularOutput" }, { "parameters": { "amount": 10 }, "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ 16, 224 ], "id": "44b4ab64-63bf-4e05-914b-d1b1bd1e115b", "name": "wait 10 secs1", "webhookId": "2645d2d0-fb2e-4b80-8063-6cca3b1238f6" }, { "parameters": { "command": "docker exec duplicati sh -lc '\nset -eux\nSRC=\"file:///backups/paperless-ngx\"\nREST=\"/docker-volumes\"\nLOG=\"/backups/_logfiles_/restore-paperless-to-volumes-192_168_2_155.log\"\n\nmkdir -p \"$(dirname \"$LOG\")\"\nrm -f \"$LOG\"\n\n/app/duplicati/duplicati-cli restore \"$SRC\" \\\n --restore-path=\"$REST\" \\\n --passphrase=\"?Aichwald01\" \\\n --overwrite=true \\\n --restore-permissions=true \\\n --restore-metadata=true \\\n --console-log-level=Information \\\n --log-file-log-level=Information \\\n --log-file=\"$LOG\" \\\n --progress\n\necho \"RC=$?\"\ntail -n 40 \"$LOG\" || true\n'" }, "type": "n8n-nodes-base.ssh", "typeVersion": 1, "position": [ 240, 224 ], "id": "0d456102-b25c-4d50-afdb-b2959b5162fe", "name": "restore auf docker volumes", "executeOnce": true, "credentials": { "sshPassword": { "id": "LFVFzTLKMe0aVTv6", "name": "SSH Password account 192.168.2.155" } } }, { "parameters": { "amount": 10 }, "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ 464, 224 ], "id": "5e6da58b-2fde-4d8c-b7ab-f2c63bc1059b", "name": "wait 10 secs2", "webhookId": "45472b2d-7668-4aae-ba5f-470592c30a65", "executeOnce": true }, { "parameters": { "rule": { "interval": [ { "triggerAtHour": 14 } ] } }, "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1.3, "position": [ -208, -160 ], "id": "7615ba2a-973e-495e-b707-fea33bf431c6", "name": "Schedule Trigger" }, { "parameters": { "chatId": "749279624", "text": "Paperless-ngx auf 192.168.2.155 wurde aktualisiert.", "additionalFields": {} }, "type": "n8n-nodes-base.telegram", "typeVersion": 1.2, "position": [ 1136, 224 ], "id": "2b37a069-dc52-4c55-8834-8285824d04ba", "name": "send a message", "webhookId": "6478310f-4cf4-4055-94d3-237a10b19382", "executeOnce": true, "credentials": { "telegramApi": { "id": "EUy2hT71fSdnEr2w", "name": "Telegram account" } } } ], "pinData": {}, "connections": { "When clicking ‘Execute workflow’": { "main": [ [ { "node": "stack config", "type": "main", "index": 0 } ] ] }, "get stack list": { "main": [ [ { "node": "select stack by name", "type": "main", "index": 0 } ] ] }, "stop stack": { "main": [ [ { "node": "wait 10 secs", "type": "main", "index": 0 } ] ] }, "wait 10 secs": { "main": [ [ { "node": "list volumes", "type": "main", "index": 0 } ] ] }, "start stack": { "main": [ [ { "node": "list containers", "type": "main", "index": 0 } ] ] }, "list containers": { "main": [ [ { "node": "send a message", "type": "main", "index": 0 } ] ] }, "stack config": { "main": [ [ { "node": "get stack list", "type": "main", "index": 0 } ] ] }, "select stack by name": { "main": [ [ { "node": "stop stack", "type": "main", "index": 0 } ] ] }, "list volumes": { "main": [ [ { "node": "filter paperless volumes", "type": "main", "index": 0 } ] ] }, "filter paperless volumes": { "main": [ [ { "node": "delete volume", "type": "main", "index": 0 } ] ] }, "delete volume": { "main": [ [ { "node": "wait 10 secs1", "type": "main", "index": 0 } ] ] }, "wait 10 secs1": { "main": [ [ { "node": "restore auf docker volumes", "type": "main", "index": 0 } ] ] }, "restore auf docker volumes": { "main": [ [ { "node": "wait 10 secs2", "type": "main", "index": 0 } ] ] }, "wait 10 secs2": { "main": [ [ { "node": "start stack", "type": "main", "index": 0 } ] ] }, "Schedule Trigger": { "main": [ [ { "node": "stack config", "type": "main", "index": 0 } ] ] } }, "active": true, "settings": { "executionOrder": "v1" }, "versionId": "16da0890-4fee-4cfe-b1be-c3d15b50d3fc", "meta": { "templateCredsSetupCompleted": true, "instanceId": "3cc6c4256e2bbdec1b3708c49dc3889c7266357f3e239651c157c2de760e6c65" }, "id": "SjOumVENunRTqS18", "tags": [ { "updatedAt": "2025-12-27T15:20:11.288Z", "createdAt": "2025-12-27T15:20:11.288Z", "id": "2gKReVMDIhJ1ungJ", "name": "Paperless-ngx" }, { "updatedAt": "2025-12-20T20:16:34.199Z", "createdAt": "2025-12-20T20:16:34.199Z", "id": "RCWZE5pB9KsORMxb", "name": "Office Automation" } ] }