From 472e490ea1f1304d26ea1686140cce4afb2485fc Mon Sep 17 00:00:00 2001 From: gospodar Date: Wed, 22 Feb 2023 19:42:00 +0100 Subject: [PATCH] Implement custom directory backup --- README.MD | 2 ++ backup.cfg | 14 ++++++++------ main.sh | 12 ++++++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.MD b/README.MD index b01ad6e..4e66bf1 100644 --- a/README.MD +++ b/README.MD @@ -47,6 +47,8 @@ All configuration options can be found in the `backup.cfg` file. The script has | db_password | ------> | Password for DB access | | db_name | ------> | Name of database | | db_all | ------> | Dump all databases instead of specific one | +| custom_backup | true/false | Enable backup of custom files | +| custom_dirs | ------> | Array of files/directories to backup ## Logs to backup array 📚 diff --git a/backup.cfg b/backup.cfg index 65b2fa1..c0565b6 100644 --- a/backup.cfg +++ b/backup.cfg @@ -2,12 +2,12 @@ # -------------------------------------------------------- # Please double check Your settings # -------------------------------------------------------- -enabled=false #enable main function -backup_path='/opt/backify/' # location of backups +enabled=false #enable the script +backup_path='/opt/backify/' # where do you want backups saved www_backup=false # backup wwwroot -www_dir='xyz' # wwwroot location -vhost_backup=false # backup vhost config -vhost_dir='/etc/httpd/sites-enabled' # vhost location +www_dir='xyz' # location of wwwroot to backup +vhost_backup=false # backup vhost configurations +vhost_dir='/etc/httpd/sites-enabled' # location of active vhost files log_backup=false # backup logs log_to_backup=("apache" "nginx" "fail2ban" "pckg_mngr" "auth" "dmesg" "dpkg" "letsencrypt" "php" "syslog" "purge") # logs to backup, options: apache, nginx, fail2ban, pckg_mngr, auth, dmesg, dpkg, letsencrypt, php, syslog, purge (truncate all)) @@ -26,4 +26,6 @@ database_type=mysql #mysql or postgresql db_username=user #database user db_password=user #database password db_all=false #dumps all databases if true -db_name=user #name of the database \ No newline at end of file +db_name=user #name of the database +custom_backup=false #backup custom files or directories +custom_dirs=("/opt/example" "/var/log/script.log") #array of custom files and/or directories to backup \ No newline at end of file diff --git a/main.sh b/main.sh index 07b8561..6b40ab9 100644 --- a/main.sh +++ b/main.sh @@ -331,6 +331,16 @@ function backup_db { fi } +function custombackup { + if [ "$custom_backup" = "true" ]; then + mkdir -p "$tmpdir/custom" + for i in "${custom_dirs[@]}" + do + cp -r $i $tmpdir/custom/ + done + fi +} + function runbackup { # init, config check init @@ -351,6 +361,8 @@ function runbackup { if [ "$db_backup" = true ]; then backup_db fi + # step 7 : custom backup + custombackup # archive data echo "Creating backup archive..." >&2 tar -czvf $backup_path/backify-$timestamp.tar.gz $tmpdir