A clean and efficient automated backup system that archives folders, uploads them to CloudFlare R2 storage, and sends Discord or Telegram notifications with download links.
- ποΈ Archive Multiple Folders: Combines multiple directories into a single compressed tar.gz archive
- βοΈ CloudFlare R2 Upload: Automatically uploads backups to CloudFlare R2 storage
- π’ Multiple Notification Methods: Supports Discord webhooks and Telegram bot notifications
- β° Flexible Scheduling: Configure backup intervals using cron syntax
- π Automatic Execution: Runs in the background as a service
- π― Manual Backup: Option to run a single backup on demand
- Go 1.19 or higher
- CloudFlare R2 storage account with credentials
- Discord webhook URL and/or Telegram bot (at least one notification method required)
git clone https://github.com/IndrajeethY/CloudFlareBackuper.git
cd CloudFlareBackuper
go build -o cloudflare-backuper- Copy the example configuration file:
cp config.example.yml config.yml- Edit
config.ymlwith your settings:
# CloudFlare R2 Storage Configuration
cloudflare:
uri: "https://your_domain.com"
bucket: "your_bucket_name"
access_key_id: "your_access_key_id_here"
secret_key: "your_secret_access_key_here"
account_id: "your_account_id_here"
# Discord Webhook Configuration (optional)
discord:
webhook_url: "https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN"
# Telegram Bot Configuration (optional)
# At least one notification method (Discord or Telegram) must be configured
telegram:
bot_token: "YOUR_BOT_TOKEN"
chat_id: "YOUR_CHAT_ID"
# Backup Configuration
backup:
# Cron schedule format: "minute hour day month weekday"
schedule: "0 */6 * * *" # Every 6 hours
# Folders to backup (will be combined into one archive)
folders:
- "/path/to/folder1"
- "/path/to/folder2"
# Backup filename prefix
name_prefix: "backup"
# Number of backups to keep (0 = keep all backups)
# When set to 5, only the last 5 backups will be kept
# Older backups are automatically deleted with notification
retention_limit: 5"0 */6 * * *"- Every 6 hours"0 0 * * *"- Daily at midnight"0 2 * * 0"- Weekly on Sunday at 2 AM"0 3 * * 1"- Weekly on Monday at 3 AM"*/30 * * * *"- Every 30 minutes
# Run with default config file (config.yml)
./cloudflare-backuper
# Run with custom config file
./cloudflare-backuper -config /path/to/config.ymlThe application will:
- Run an initial backup immediately on startup
- Schedule future backups based on the cron schedule
- Continue running until stopped with Ctrl+C
# Run one backup and exit
./cloudflare-backuper -once
# Run one backup with custom config
./cloudflare-backuper -config /path/to/config.yml -onceCreate a service file at /etc/systemd/system/cloudflare-backuper.service:
[Unit]
Description=CloudFlare Backuper Service
After=network.target
[Service]
Type=simple
User=your-username
WorkingDirectory=/path/to/CloudFlareBackuper
ExecStart=/path/to/CloudFlareBackuper/cloudflare-backuper
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetEnable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable cloudflare-backuper
sudo systemctl start cloudflare-backuper
sudo systemctl status cloudflare-backuperThe application supports multiple notification methods. You can use Discord, Telegram, or both simultaneously. At least one notification method must be configured.
The application sends rich embed notifications to Discord with:
- β Green embed with "Backup Successful" title
- File name
- File size (human-readable format)
- Download link
- Timestamp
- β Red embed with "Backup Failed" title
- Error details
- Timestamp
- ποΈ Yellow embed with "Old Backup Deleted" title
- Deleted file name
- Previous download link
- Timestamp
To set up Telegram notifications:
-
Create a Telegram Bot:
- Talk to @BotFather on Telegram
- Send
/newbotcommand - Follow the instructions to create your bot
- Copy the bot token provided
-
Get Your Chat ID:
- Start a chat with your bot
- Send any message to your bot
- Visit:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates - Find your
chat_idin the JSON response
-
Configure in config.yml:
telegram: bot_token: "1234567890:ABCdefGHIjklMNOpqrsTUVwxyz" chat_id: "123456789"
The application sends formatted messages to Telegram with:
- β Backup Successful: File name, size, and download link
- β Backup Failed: Error details
- ποΈ Old Backup Deleted: Deleted file information
- Never commit your
config.ymlfile with real credentials - Keep your CloudFlare secret key secure
- Restrict Discord webhook URL access
- Keep your Telegram bot token private
- Ensure proper file permissions on the config file (chmod 600)
- Consider using environment variables for sensitive credentials
Make sure you've added the secret key to your config.yml:
cloudflare:
secret_key: "your_secret_access_key_here"Ensure config.yml exists in the current directory or specify the path with -config.
Verify that all folders listed in the config exist and are readable.
The application logs all operations to stdout. To save logs to a file:
./cloudflare-backuper 2>&1 | tee backup.logCloudFlareBackuper/
βββ backup/ # Archive creation logic
βββ config/ # Configuration parsing
βββ notification/ # Discord webhook integration
βββ scheduler/ # Cron scheduling and backup orchestration
βββ storage/ # CloudFlare R2 client
βββ main.go # Application entry point
βββ config.example.yml
βββ README.md
go build -o cloudflare-backupergo test ./...See LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.