Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • dbod/administration/sql-backup
1 result
Select Git revision
Show changes
config.json
*.swp
......@@ -22,7 +22,7 @@ to the appropriate path.
The backup script needs an SQL User, capable to lock and dump the databases, which should be backuped.
In the standard configuration, the script trys to backup every single database on the server "localhost",
using the user "root" without a password. This will most probably result in an error. See further on the Step
[Configuration](#Configuration).
[Configuration](Configuration).
## Developing
......@@ -37,16 +37,21 @@ cd sql-backup
## Configuration
The script needs the following variables to work. Therefor a file named 'config.json' is loaded. If the file does not exist, a standard configuration will be loaded.
The script needs the following variables to work. Therefor a file named 'config.json' is loaded. If the file
does not exist, a standard configuration will be loaded.
| Variable type | variable name | default Value |
|-----------------------|------------------|-------------------|
| SQL Server Hostname | sqlHost | localhost |
| SQL Server Port | sqlPort | 3306 |
| User used to connect | sqlUser | root |
| List of Databases | dbNames | ($(mysql -u $sqlUser -e "SHOW DATABASES;")) |
| User Password | sqlPass | null |
| List of Databases | dbNames | all |
| Backup Root Directory | backupRoot | /var/backups/sql/ |
| Days to keep Backups | backupRetainDays | 30 |
| Rsync Destination | rsyncDest | null |
Rsync destination can only lead to a 'local' directory. To use an offsite destination, mount it via system.
## Contributing
......
......@@ -6,6 +6,7 @@
"sqlPass": null,
"dbNames": "all",
"backupRoot": "/var/backups/sql/",
"backupRetainDays": 30
"backupRetainDays": 30,
"rsyncDest": null
}
]
......@@ -37,6 +37,7 @@ if [ $dbNames == 'all' ]; then
fi
backupRoot=$(cat $configFile | jq -r '.[0].backupRoot')
backupRetainDays=$(cat $configFile | jq -r '.[0].backupRetainDays')
rsyncDest=$(cat $configFile | jq -r '.[0].rsyncDest')
today=$(date +"%y%m%d")
......@@ -70,7 +71,7 @@ do
continue
fi
backupPath=$backupRoot$dbName
backupPath=$backupRoot/$dbName
mkdir -p ${backupPath}
if [ -z $sqlPass ];
......@@ -106,3 +107,8 @@ do
continue
fi
done
if [ ! -z $rsyncDest ]; then
echo 'INFO: Rsync destination defined. Start rsync.'
rsync -r --delete $backupRoot $rsyncDest
fi