Skip to content
Snippets Groups Projects
Commit 447297ac authored by root's avatar root
Browse files

create project, add prototype files

parents
No related branches found
No related tags found
No related merge requests found
![Logo of the project](https://raw.githubusercontent.com/jehna/readme-best-practices/master/sample-logo.png)
# 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.
## Installing / Getting started
Clone the repository and execute the install script.
```shell
git clone https://git.slub-dresden.de/dbod/sql-backup.git
cd sql-backup
sudo bash 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.
### 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.
## Developing
To participate in the development of the project, you just need to clone the repository.
```shell
git clone https://git.slub-dresden.de/dbod/sql-backup.git
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
Copy-paste as many of these as you need.
## Contributing
"If you'd like to contribute, please fork the repository and use a feature
branch. Pull requests are warmly welcome."
## Links
- 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
to improve the security and privacy of this project!
- Related projects:
- Template for the README.md: https://github.com/jehna/readme-best-practices
## Licensing
"The code in this project is licensed under MIT license."
[Unit]
Description=Create sql backup and delete backups older then specified (in script) days
Wants=sql-backup.timer
[Service]
Type=oneshot
ExecStart=./sql-backup.sh
[Install]
WantedBy=multi-user.target
#!/bin/bash
export PATH=/bin:/usr/bin:/usr/local/bin
today=$(date +"%y%m%d")
sqlHost="localhost"
sqlPort="3306"
sqlUser="backup"
sqlPass="l)m0h4vtJ@D7*f5YOvLO5c=0g?4K3aEM"
dbName="booked_prod"
backupPath="/var/backups/sql/"$dbName
backupRetainDays=30
mkdir -p ${backupPath}
cd $backupPath
mysqldump -h ${sqlHost} \
-P${sqlPort} \
-u${sqlUser} \
-p${sqlPass} \
${dbName} > ${backupPath}/${dbName}-${today}.sql
if [ $? -eq 0 ]; then
echo "Database backup successfully completed"
else
echo "Error found during backup"
fi
delDate=$(date +"%y%m%d" --date="${BACKUP_RETAIN_DAYS} days ago")
delFile=${dbName}-${delDate}.sql
for f in *
do
if [[ "$f" < "$delFile" ]]
then
echo "delete $f"
rm -f $f
else
echo "keep $f"
fi
done
[Unit]
Description=Execute sql-backup.service on a daily basis.
Requires=sql-backup.service
[Timer]
Unit=sql-backup.service
OnCalendar=*-*-* 12: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