From f53b1d381d746dd0c8faed7a25d7ad1ae5ebbfbe Mon Sep 17 00:00:00 2001 From: gospodar Date: Wed, 22 Feb 2023 20:05:34 +0100 Subject: [PATCH] DB backup implement host and port parameter / backup path fix --- README.MD | 6 +++++- backup.cfg | 4 +++- main.sh | 9 +++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.MD b/README.MD index 4e66bf1..db5d85c 100644 --- a/README.MD +++ b/README.MD @@ -15,6 +15,8 @@ Backify is a shell script that helps you automate the backup process of all kind - The system must be either a Red Hat-based or an Ubuntu-based distribution. +- mysqldump / pgdump if dumping database on a diferent host + ## Configuration 🧙‍♂️ @@ -24,7 +26,7 @@ All configuration options can be found in the `backup.cfg` file. The script has | Name | Value | Specifics | | --- | --- | --- | | enabled | true/false | Disable the main function | -| backup_path | ------> | Set where to save the backup | +| backup_path | ------> | Set where to save the backup, make sure it DOESNT end with backslash | | www_backup | true/false | Backup of the webroot directory | | www_dir | ------> | Path to the webroot | | vhost_backup | true/false | Backup of the vhost configuration | @@ -43,6 +45,8 @@ All configuration options can be found in the `backup.cfg` file. The script has | docker_data | true/false | Backup container information | | db_backup | true/false | Backup database | | database_type | mysql/postgresql | Database type | +| db_host | ------> | Database host | +| db_port | ------> | Port for DB access | | db_username | ------> | Username for DB access | | db_password | ------> | Password for DB access | | db_name | ------> | Name of database | diff --git a/backup.cfg b/backup.cfg index c0565b6..50f51d1 100644 --- a/backup.cfg +++ b/backup.cfg @@ -3,7 +3,7 @@ # Please double check Your settings # -------------------------------------------------------- enabled=false #enable the script -backup_path='/opt/backify/' # where do you want backups saved +backup_path='/opt/backify' # where do you want backups saved, make sure it doesnt end in backslash www_backup=false # backup wwwroot www_dir='xyz' # location of wwwroot to backup vhost_backup=false # backup vhost configurations @@ -23,6 +23,8 @@ docker_volumes=false #backup docker volumes docker_data=false #backup container information db_backup=false #backup databases database_type=mysql #mysql or postgresql +db_host='localhost' #hostname of mysql server +db_port=3306 #port for db access db_username=user #database user db_password=user #database password db_all=false #dumps all databases if true diff --git a/main.sh b/main.sh index 6b40ab9..4ac7cdc 100644 --- a/main.sh +++ b/main.sh @@ -316,17 +316,18 @@ function dockerbackup { } function backup_db { + mkdir -p $tmpdir/db if [ "$db_all" = true ]; then if [ "$database_type" = "mysql" ]; then - mysqldump -u "$db_username" -p"$db_password" --all-databases >$tmpdir/db/db_all.sql + mysqldump -u "$db_username" -p"$db_password" -h "$db_host" -P"$db_port" --all-databases >$tmpdir/db/db_all.sql elif [ "$database_type" = "postgresql" ]; then - pg_dumpall -U "$db_username" -f $tmpdir/db/db_all.sql + pg_dumpall -U "$db_username" -h "$db_host" -f $tmpdir/db/db_all.sql fi else if [ "$database_type" = "mysql" ]; then - mysqldump -u "$db_username" -p"$db_password" "$db_name" >$tmpdir/db/$db_name.sql + mysqldump -u "$db_username" -p"$db_password" -h "$db_host" -P"$db_port" "$db_name" >$tmpdir/db/$db_name.sql elif [ "$database_type" = "postgresql" ]; then - pg_dump -U "$db_username" "$db_name" -f $tmpdir/db/$db_name.sql + pg_dump -U "$db_username" -h "$db_host" "$db_name" -f $tmpdir/db/$db_name.sql fi fi }