This Bash script provides a robust solution for backing up server directories and a MySQL database. It reads configuration settings from an external file (backup.conf
), performs the backups, logs the process, and securely encrypts the backup files.
Before you begin, ensure you have the following installed and configured on your system:
- Bash Shell: Available on Linux and UNIX-like operating systems.
- MySQL Server: Needed for database backups.
- OpenSSL: Required for encrypting the backup files.
- tar: Utility for archiving directories.
- Access Permissions: Ensure the script has the necessary permissions to access the directories and databases you intend to back up.
Set up your backup configuration by editing the backup.conf
file. Adjust the file paths, database credentials, and other settings according to your specific needs.
# Database settings
DB_USER=root
DB_PASSWORD=password
DB_NAME=my_database
# Backup settings
ENCRYPTION_PASSWORD=my_secure_password
BACKUP_ROOT_DIR=/path/to/backup
SOURCE_DIRS=/home/user/data,/home/user/docs
# Log file location
LOG_FILE=/path/to/backup.log
-
Download the Script: Clone this repository or directly download the
backup.sh
andbackup.conf
files to your server. -
Set File Permissions: Secure the script and configuration file:
chmod 700 backup.sh chmod 600 backup.conf
-
Configure the
backup.conf
File: Ensure the configuration file is placed either in the same directory asbackup.sh
or specify its location in the script.
Execute the script with the following command:
./backup.sh
To automate the backup process, add a cron job:
crontab -e
Insert the following line to run the backup daily at 2 AM:
0 2 * * * /path/to/backup.sh > /dev/null 2>&1
- Protect Sensitive Data: Ensure the
backup.conf
is kept secure, as it contains sensitive information. - Restrict Access: Limit access to the script, configuration file, and backup data to trusted users only.
- Regular Testing: Frequently test the backup and restore process to confirm the integrity and recoverability of the data.
Monitor the backup process through the log file specified in backup.conf
. Check this file regularly for any errors or confirmations of successful backups:
cat /path/to/backup.log
For any issues, suggestions, or contributions, please contact the repository maintainer or submit an issue/pull request to the project's GitHub page.