Bash script for advanced server backup
Go to file
2023-02-22 17:35:59 +01:00
.gitignore Bug fixes / Git ignore for parsed backup.cfg 2023-02-10 21:44:40 +01:00
backup.cfg Upgrades on log backup logic 2023-02-22 17:35:59 +01:00
main.sh Upgrades on log backup logic 2023-02-22 17:35:59 +01:00
README.MD Upgrades on log backup logic 2023-02-22 17:35:59 +01:00

Backify 🗃️

What is Backify? 👾

Backify is a shell script that helps you automate the backup process of all kinds of data from Linux systems. It differs from other backup scripts because it gives you the flexibility to choose what you want to save, ranging from system logs to containers. The script was tailored to meet personal needs as there was no complete solution for the specific use case.

Prerequisites 👷

  • The script must be executed as root.

  • A configuration file named backup.cfg must exist in the same directory as the script.

  • The system must be either a Red Hat-based or an Ubuntu-based distribution.

Configuration 🧙‍♂️

All configuration options can be found in the backup.cfg file. The script has an integrity check in place to ensure that no external commands can be embedded into it by malware. The following table provides an overview of the available configuration options:

Name Value Specifics
enabled true/false Disable the main function
backup_path ------> Set where to save the backup
www_backup true/false Backup of the webroot directory
www_dir ------> Path to the webroot
vhost_backup true/false Backup of the vhost configuration
vhost_dir ------> Path to the vhost files
log_backup true/false Backup log files
log_to_backup array Array of logs to backup, options: apache, nginx, fail2ban, alternatives, pckg_mngr, auth, dmesg, dpkg, letsencrypt, php, syslog
rsync_push true/false Push the backup file to a remote server
push_clean true/false Delete the backup file after push
target_host ------> Backup push target host
target_user ------> Backup push target username
target_key ------> Backup target ssh key
target_dir ------> Backup target push to location
docker_enable true/false Enable Docker backups
docker_images true/false Backup Docker images
docker_volumes true/false Backup Docker volumes
docker_data true/false Backup container information
db_backup true/false Backup database
database_type mysql/postgresql Database type
db_username ------> Username for DB access
db_password ------> Password for DB access
db_name ------> Name of database
db_all ------> Dump all databases instead of specific one

Script Execution 🪄

To execute the script, simply run the following command in the terminal:

./backify.sh

The script will first initialize by checking for the existence of the configuration file, loading its parameters, and verifying that the script is being executed as root.

Then, it will determine whether the system is a Red Hat-based or an Ubuntu-based distribution.

Finally, the script will create a new directory with a timestamped name in the backup_path directory, where the backups will be stored.

The components specified in the configuration file will then be backed up to the newly created directory.

Automation 🤖

Here's an example of how you can use cron on Linux to run your script every day at 12 PM:

Open the terminal and type crontab -e to open the cron table for editing.

Add the following line to the end of the file:

0 12 * * * /path/to/your/script.sh

Save and exit the file.