Situatie
Solutie
Step 1 – Install Required Packages
Update the system and install the tools.
sudo apt install rsync rclone
For CentOS/RHEL:
Step 2 – Configure Cloud Storage Access
Run the rclone configuration wizard.
Configuration steps:
-
Choose n for new remote
-
Enter a name for the remote (example:
cloud-backup) -
Select the cloud provider (Google Drive, S3, etc.)
-
Complete authentication
Test the connection:
If files are listed, the connection works correctly.
Step 3 – Create a Local Backup Directory
Create a directory where backups will be temporarily stored.
Create a basic backup structure.
sudo mkdir -p /backup/weekly
sudo mkdir -p /backup/monthly
Example structure:
├── daily
├── weekly
└── monthly
Step 4 – Create the Backup Script
Create a script that performs the backup and uploads it to cloud storage.
Add the following content:
#!/bin/bash
DATE=$(date +%Y-%m-%d)
SOURCE=“/var/www”
BACKUP_DIR=“/backup/daily/$DATE“
mkdir -p $BACKUP_DIR
rsync -av –delete $SOURCE $BACKUP_DIR
rclone sync $BACKUP_DIR cloud-backup:server-backups/$DATE
Explanation:
-
rsyncperforms an incremental backup -
rcloneuploads the backup to cloud storage -
backups are organized by date
Save and exit the editor.
Step 5 – Make the Script Executable
Give execution permission to the script.
Test the script manually.
Verify that the backup directory is created and files appear in cloud storage.
Step 6 – Automate the Backup with Cron
Open the cron scheduler.
Add the following line:
This means:
-
the backup runs every day at 02:00 AM
Step 7 – Remove Old Backups Automatically
To avoid filling up disk space, add a cleanup command to the script.
Edit the script again.
Add this line at the end:
This removes backups older than 7 days.
Step 8 – Verify Backup Integrity
You can periodically verify that backups are correct.
Check cloud synchronization:
Optional checksum verification:
Step 9 – Enable Logging
Logging helps diagnose problems if backups fail.
Modify the cron job:
Now all output and errors will be saved in:
View logs with:
The system now:
-
performs automated daily backups
-
stores them locally and in cloud storage
-
deletes backups older than 7 days
-
records activity in log files
This provides a simple but reliable automated backup infrastructure for Linux servers.
Leave A Comment?