DB backup implement host and port parameter / backup path fix

This commit is contained in:
gospodar 2023-02-22 20:05:34 +01:00
parent 472e490ea1
commit f53b1d381d
3 changed files with 13 additions and 6 deletions

View File

@ -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. - The system must be either a Red Hat-based or an Ubuntu-based distribution.
- mysqldump / pgdump if dumping database on a diferent host
## Configuration 🧙‍♂️ ## Configuration 🧙‍♂️
@ -24,7 +26,7 @@ All configuration options can be found in the `backup.cfg` file. The script has
| Name | Value | Specifics | | Name | Value | Specifics |
| --- | --- | --- | | --- | --- | --- |
| enabled | true/false | Disable the main function | | 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_backup | true/false | Backup of the webroot directory |
| www_dir | ------> | Path to the webroot | | www_dir | ------> | Path to the webroot |
| vhost_backup | true/false | Backup of the vhost configuration | | 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 | | docker_data | true/false | Backup container information |
| db_backup | true/false | Backup database | | db_backup | true/false | Backup database |
| database_type | mysql/postgresql | Database type | | database_type | mysql/postgresql | Database type |
| db_host | ------> | Database host |
| db_port | ------> | Port for DB access |
| db_username | ------> | Username for DB access | | db_username | ------> | Username for DB access |
| db_password | ------> | Password for DB access | | db_password | ------> | Password for DB access |
| db_name | ------> | Name of database | | db_name | ------> | Name of database |

View File

@ -3,7 +3,7 @@
# Please double check Your settings # Please double check Your settings
# -------------------------------------------------------- # --------------------------------------------------------
enabled=false #enable the script 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_backup=false # backup wwwroot
www_dir='xyz' # location of wwwroot to backup www_dir='xyz' # location of wwwroot to backup
vhost_backup=false # backup vhost configurations vhost_backup=false # backup vhost configurations
@ -23,6 +23,8 @@ docker_volumes=false #backup docker volumes
docker_data=false #backup container information docker_data=false #backup container information
db_backup=false #backup databases db_backup=false #backup databases
database_type=mysql #mysql or postgresql 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_username=user #database user
db_password=user #database password db_password=user #database password
db_all=false #dumps all databases if true db_all=false #dumps all databases if true

View File

@ -316,17 +316,18 @@ function dockerbackup {
} }
function backup_db { function backup_db {
mkdir -p $tmpdir/db
if [ "$db_all" = true ]; then if [ "$db_all" = true ]; then
if [ "$database_type" = "mysql" ]; 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 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 fi
else else
if [ "$database_type" = "mysql" ]; then 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 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
fi fi
} }