You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rSyncBackup Script (automating backups across multiple servers)
This Bash script automates the process of backing up files from specified remote servers to designated local directories using rsync. It includes logging capabilities for monitoring the backup operations and handles password authentication using sshpass.
🌟 Key Features
Automated Backup: The script facilitates automatic backups from specified remote servers to designated local directories, eliminating the need for manual intervention.
Efficient Transfer: Utilizing rsync, the script efficiently transfers files by only copying changed data, which minimizes bandwidth usage and speeds up the process.
Logging Capabilities: It logs essential information such as the start and end times of backup operations, along with any errors encountered during the process. This ensures that users can monitor and review backup activities effectively.
Archiving Previous Backups: To prevent data loss, the script archives previous backups with timestamps. This feature allows users to maintain historical versions of their data.
🌟 Implementation Details
Prerequisites: The script requires bash, rsync, and sshpass for password authentication. It is also recommended to set up passwordless SSH access for seamless operation.
Scheduling: The script can be scheduled to run at regular intervals using a cron job, ensuring that backups are performed consistently without user input.
Error Handling: While basic logging is included, users are advised to implement additional error handling mechanisms to address potential issues during backup operations.
Usage Scenarios: The script can be adapted for various use cases, such as backing up web server files, databases, or personal data across different systems.
This automation not only enhances data security by ensuring regular backups but also simplifies the management of backup processes across multiple servers.
💡 Configuration Section :
declare -A SOURCE_SERVERS=(
["user@192.168.162.11:22:/backends"]="password11:/mnt/storage/backup/backends-11"
["user@192.168.162.12:2223:/etc/nginx"]="password12:/mnt/storage/backup/nginx-12"
)
ARCHIVE_BASE="/mnt/storage/backup/archive"
LOG_DESTINATION="/mnt/storage/backup"
CURRENT_DATE=$(date +"%Y-%m-%d_%H-%M-%S")
Associative Array: SOURCE_SERVERS holds the mapping of source server details (user, IP, port, and path) to their respective passwords and local backup destinations.
Directories: ARCHIVE_BASE is where previous backups are stored, and LOG_DESTINATION is where log files are saved.
Current Date: The current date and time are captured for use in logging and archiving.
📜 Conclusion
This Bash script is a robust solution for automating backups across multiple servers while ensuring data integrity through archiving and comprehensive logging. By using tools like rsync and sshpass, it simplifies file transfers while managing passwords securely within a controlled environment.
— Feedback ❤️—
Please leave a comment if you have any comments, suggestions or problems.
About
The rSyncBackup Bash script automates the backup process by utilizing rsync to transfer files from specified remote servers to local directories.