Skip to content
Snippets Groups Projects
Commit 8866e9e7 authored by root's avatar root
Browse files

Added .gitignore. Repaired systemd unit. Added installation script (currently...

Added .gitignore. Repaired systemd unit. Added installation script (currently missing update routine).
parent 019fa8b9
No related branches found
No related tags found
No related merge requests found
config.json
# Automated SQL Backup Script
A simple bash script, to automatically create sql dumps on a daily basis, scheduled by systemd.
It comes with a built in mechanism to check and delete old backups.
A simple bash script, to automatically create SQL dumps on a daily basis, scheduled by systemd.
It comes with a built-in mechanism to check and delete old backups.
## Installing / Getting started
Clone the repository and execute the install script.
Clone the repository and execute the installation script.
```shell
git clone https://git.slub-dresden.de/dbod/sql-backup.git
cd sql-backup
sudo bash install.sh
sudo git clone https://git.slub-dresden.de/dbod/sql-backup.git /opt/sql-backup
sudo bash /opt/sql-backup/install.sh
systemctl enable sql-backup.service
```
After the repository is cloned, the install script is executed. The script first checks for repository updates.
After that it is copying the systemd service files (.service and .timer) to the systemd path.
It then edits the .service file with sed, to properly define the path to the backup script.
After the repository is cloned, the installation script is executed. The script first triggers the update script
and checks for repository updates. After that, it is copying the systemd service files (.service and .timer)
to the appropriate path.
### Initial Configuration
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.
using the user "root" without a password. This will most probably result in an error. See further on the Step
[Configuration](#Configuration).
## Developing
......@@ -35,33 +35,18 @@ cd sql-backup
## Features
What's all the bells and whistles this project can perform?
* What's the main functionality
* You can also do another thing
* If you get really randy, you can even do this
## Configuration
Here you should write what are all of the configurations a user can enter when
using the project.
#### Argument 1
Type: `String`
Default: `'default value'`
State what an argument does and how you can use it. If needed, you can provide
an example below.
Example:
```bash
awesome-project "Some other value" # Prints "You're nailing this readme!"
```
#### Argument 2
Type: `Number|Boolean`
Default: 100
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.
Copy-paste as many of these as you need.
| 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;")) |
| Backup Root Directory | backupRoot | /var/backups/sql/ |
| Days to keep Backups | backupRetainDays | 30 |
## Contributing
......@@ -73,7 +58,7 @@ branch. Pull requests are warmly welcome."
- Repository: https://git.slub-dresden.de/dbod/sql-backup
- Issue tracker: https://git.slub-dresden.de/dbod/sql-backup/-/issues
- In case of sensitive bugs like security vulnerabilities, please contact
hannes.braun@email.com directly instead of using issue tracker. We value your effort
hannes.braun@slub-dresden.de directly instead of using issue tracker. We value your effort
to improve the security and privacy of this project!
- Related projects:
- Template for the README.md: https://github.com/jehna/readme-best-practices
......
#!/bin/bash
if [[ ! -d /opt/sql-backup ]];
then
echo "ERROR: Could not find sql-backup repository in /opt/sql-backup. Please clone git repository to the" \
"correct Path."
exit 1
else
cd /opt/sql-backup
fi
if [[ ! -f ./config.json ]]
then
echo "WARN: No configuration file found. Creating one with default values from config_template.json."
cp ./config_template.json ./config.json
fi
if [[ ! -f /etc/systemd/system/sql-backup.service ]];
then
echo "WARN: existing service file found. Overwriting."
fi
cp -r ./service-unit/sql-backup.service /etc/systemd/system
if [[ ! -f /etc/systemd/system/sql-backup.timer ]];
then
echo "WARN: existing service file found. Overwriting."
fi
cp -r ./service-unit/sql-backup.timer /etc/systemd/system
systemctl enable sql-backup.service
......@@ -3,8 +3,8 @@ Description=Create sql backup and delete backups older then specified (in script
Wants=sql-backup.timer
[Service]
Type=oneshot
ExecStart=
Type=simple
ExecStart=/opt/sql-backup/sql-backup.sh
[Install]
WantedBy=multi-user.target
......@@ -4,7 +4,7 @@ Requires=sql-backup.service
[Timer]
Unit=sql-backup.service
OnCalendar=*-*-* 12:00:00
OnCalendar=*-*-* 02:00:00
[Install]
WantedBy=timers.target
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment