Automated Cloud Storage Backup Pruning and Telegram Notifications - n8n Workflow

Use this robust n8n workflow to automatically clean up Cloudflare R2 (S3 compatible) buckets, deleting backups or files older than 14 days and sending confirmation notifications via Telegram. Essential n8n templates for DevOps.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

DevOps engineers needing automated data lifecycle management.
Users utilizing Cloudflare R2 or AWS S3 for long-term backup storage.
Administrators seeking confirmation alerts for cleanup tasks via Telegram.
Anyone looking for practical n8n templates for infrastructure maintenance.

Overview

Managing cloud storage costs and compliance often requires regularly deleting aged files. Manually performing these tasks can be tedious and prone to error. This solution provides a reliable, scheduled mechanism for data cleanup.

This specific n8n workflow acts as a cleanup agent, using the S3 API (compatible with Cloudflare R2) to list all objects. It then uses a custom n8n node to filter the list, retaining only files that are older than 14 days. Finally, it executes a batch delete operation and reports the outcome via Telegram.

By leveraging this n8n workflow, users can significantly reduce manual effort and ensure that their storage buckets are kept tidy, making this one of the most useful n8n templates for cloud operations.

How it Works

The automated process begins with the Schedule Trigger n8n node.


  1. Trigger and List: The n8n trigger initiates the workflow daily at a set time (e.g., 9 AM). It then calls the first S3 n8n node to fetch a complete list of all files and their metadata (including LastModified date) from the designated Cloudflare R2 bucket.

  2. Filtering Logic: The data flows into the Code n8n node. This node contains JavaScript logic that calculates the age of each file based on its LastModified timestamp. It filters the dataset, passing only the items where the age exceeds 14 days (TWO_WEEKS).

  3. Deletion: The filtered list is sent to the second S3 n8n node, which is configured for the delete operation. For every item received, this n8n node executes a corresponding delete command using the file's Key.

  4. Notification: After the deletion is confirmed, the final Telegram n8n node sends a detailed notification to a configured chat ID, confirming that the R2 backup cleanup is complete and listing the key of the deleted item. This ensures visibility for the administrator running the n8n workflow.

Installation Guide

To deploy this n8n workflow, follow these steps:


  1. Import: Copy the provided JSON code and paste it into your n8n instance via the 'New' menu -> 'Import from JSON'.

  2. S3/R2 Credentials: Click on both S3 n8n node instances. You must set up or select existing AWS S3 credentials that point to your Cloudflare R2 or S3 bucket. Ensure you have the correct Access Key ID, Secret Access Key, and Endpoint URL (for R2).

  3. Bucket Name: Update the bucketName parameter in both S3 n8n nodes to match your actual bucket.

  4. Telegram Setup: Configure the Telegram n8n node with the appropriate credentials (Bot Token) and set the chatId to the specific group or user you wish to receive notifications.

  5. Activation: Ensure the n8n trigger is set to the desired schedule and activate the n8n workflow.

Node Details

Schedule Trigger n8n trigger:
Function: Starts the n8n workflow daily at the configured hour (9 AM).
Key Configuration: triggerAtHour is set to 9.
S3 (List) n8n node:
Function: Connects to the cloud storage (Cloudflare R2 or AWS S3) and retrieves metadata for all objects within the specified bucket.
Key Configuration: Operation: getAll, Return All: true, Credentials: Cloudflare S3 account.
Code n8n node:
Function: Filters the file list based on age. It calculates if the LastModified date is older than 14 days (14 24 60 60 1000 milliseconds).
Key Configuration: Custom JavaScript logic defining the TWO_WEEKS constant and filtering objects accordingly.
S3 (Delete) n8n node:
Function: Deletes the specific file keys passed down from the filtering step.
Key Configuration: Operation: delete, File Key: ={{ $json.Key }} (uses data passed from the previous n8n node).
Telegram n8n node:
Function: Sends a confirmation message after a file has been successfully removed.
* Key Configuration: Text: Includes interpolation of the deleted file key ({{ $('Code').item.json.Key }}) for clear reporting.

Related n8n Workflows

Free

Nodes: 5 Nodes
Updated: December 26 2025
View all
Created by
Mobder
Mobder

Featured*