Automated Backup Using rsync and API Notification

An automated backup solution that utilizes rsync for efficient file synchronization and integrates with an API to notify system owners of the backup status. The script facilitates the process of backing up files from a local directory to a remote server, logs detailed transfer information, and sends notifications to a specified API endpoint once the backup is complete.

This solution was designed to streamline the backup process, ensuring reliability with minimal manual intervention, and providing system owners with real-time updates on the status of their backups.

Key Features:

Backup Automation: Uses rsync to sync files from a local directory to a remote server efficiently.
Detailed Logs: Provides comprehensive logs that include the total size of transferred files and other statistics.
API Notification: Sends a detailed JSON payload to a specified API endpoint, notifying the system owner about the backup status.
SSH Authentication: Utilizes SSH key-based authentication for secure and encrypted file transfers.
Cron Job Integration: Easily scheduled to run at regular intervals for automated backups.


Technologies Used:
rsync: A fast and versatile tool for syncing files and directories.
SSH: For secure communication between the local and remote servers.
curl: To send HTTP POST requests with backup data to the API endpoint.
API: A custom PHP Mailer API that handles email notifications based on the backup status.
Cron Jobs: For automating the script execution at scheduled intervals.


How It Works:

The script automates the backup process by syncing files from a local directory to a remote server using rsync. After the transfer is complete, the script logs key details, such as the total size of the transferred files, and sends these details to an API endpoint in the form of a JSON payload. This notification triggers an email(via the PHP Mailer API) to the system owner, informing them whether the backup was successful or if any issues occurred.


Backup Process
The script begins by setting up the local and remote directories, SSH key, and other necessary configurations. It then runs rsync to synchronize the files. After theprocess completes, the script captures the start and end times, along with the total size of the transferred files.

API Notification:

Once the backup is complete, a JSON payload containing the backup status, start and end times, file details, and server information is sent to the API endpoint.This triggers the corresponding email notifications, keeping the system owner informed of the backup’s status.

Download Source code

The source code for this project is not publicly available.
Please fill out the contact form below, and I’ll get back to you with the necessary details.