Skip to content

Commit 3a3fb50

Browse files
alievertzAndy Lievertz
andauthored
All features implented; v1.0.0 (#1)
Co-authored-by: Andy Lievertz <alievertz@onezeroone.dev>
1 parent b0b2a04 commit 3a3fb50

6 files changed

Lines changed: 328 additions & 178 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# OZO MariaDB Backup Change Log
2+
3+
|Date|Version|Comment|
4+
|----|-------|-------|
5+
|2023-Mar-17|1.0.0|Initial release.|

README.md

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,52 @@
1-
# OZO MariaDB Backup
1+
# OZO MariaDB Backup Installation and Configuration
22

33
## Overview
4-
This script is intended to run daily and creates a dump of all MariaDB databases (and will work with MySQL, too).
4+
This script creates a dump of all MariaDB databases and performs history maintenance. It runs with no arguments. When executed, it iterates through the MariaDB databases and creates a compressed dump file in `MARIADB_DUMP_DIR` (typically `/var/lib/mysql-dump`). Upon successfully dumping a database, it will delete any dump files older than `MARIADB_DUMP_KEEP_DAYS` days. This script should work with MySQL, too.
55

6-
It runs with no arguments. When executed, it iterates through the MariaDB databases and creates a compressed dump file in MARIADB_DUMP_DIR e.g., `/var/lib/mysql-dump`. Upon successfully dumping a database, it will delete any dump files older than MARIADB_DUMP_KEEP_DAYS days (3).
7-
8-
Please visit https://onezeroone.dev to learn more about this script and my other work.
9-
10-
## Setup and Configuration
11-
12-
Install MariaDB e.g., as follows for RedHat-style distributions:
6+
## Prerequisites
7+
Install MariaDB, start services, and create a `mysql-backup` database user (substituting a strong password for '****************'.)
138

9+
### AlmaLinux, Red Hat Enterprise Linux, Rocky Linux
1410
```
15-
# dnf -y install mariadb mariadb-server
16-
```
17-
18-
Enable and start the MariaDB service e.g., as follows for RedHat-style distributions:
19-
20-
```
21-
# systemctl enable --now mariadb
11+
dnf -y install mariadb mariadb-server
12+
systemctl enable --now mariadb
13+
mysqladmin -u root password '****************'
14+
mysql -u root -p
15+
mysql> GRANT SELECT, RELOAD, LOCK TABLES, SHOW VIEW ON *.* TO 'mysql-backup'@'localhost' IDENTIFIED BY '****************';
16+
mysql> flush privileges;
17+
mysql> quit;
2218
```
19+
### Debian
20+
PENDING.
2321

24-
Set a strong password for the MariaDB `root` user, substituting your own password for `****************`:
22+
## Installation
23+
To install this script on your system, you must first register the One Zero One repository.
2524

26-
```
27-
# mysqladmin -u root password '****************'
25+
### AlmaLinux 10, Red Hat Enterprise Linux 10, Rocky Linux 10 (RPM)
26+
```bash
27+
rpm -Uvh https://repositories.onezeroone.dev/el/10/noarch/ozo-rdiff-backup-1.0.0-1.el10.noarch.rpm
28+
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-ONEZEROONE
29+
dnf repolist
30+
dnf -y install ozo-mariadb-backup
2831
```
2932

30-
Create a mysql-backup user before using this script, substituting your own password for `****************`:
31-
32-
```
33-
# mysql -u root -p
34-
mysql> GRANT SELECT, RELOAD, LOCK TABLES, SHOW VIEW ON *.* TO 'mysql-backup'@'localhost' IDENTIFIED BY '****************';
35-
mysql> flush privileges;
36-
mysql> quit;
37-
```
33+
### Debian (DEB)
34+
PENDING.
3835

39-
### Clone the Repository and Copy Files
36+
## Configuration
37+
### Modify /etc/ozo-mariadb-backup.conf
38+
Set `MARIADB_DUMP_PASS` with the password you create for `mysql-backup` in the prerequisite steps, above. Review the remaining variables and adjust as needed to suit your environment.
4039

41-
Clone this repository to a temporary directory. Then (as `root`):
40+
|Variable|Example Value|Description|
41+
|--------|-------------|-----------|
42+
|MARIADB_DUMP_USER|`"mysql-backup"`|The user that was granted permission to dump all databases.|
43+
|MARIADB_DUMP_PASS|`"****************"`|The password for the `MARIADB_DUMP_USER` user.|
44+
|MARIADB_DUMP_DIR|`"/var/lib/mysql-dump"`|The output directory for compressed dump files. The script will attempt to create this directory if it does not already exist.|
45+
|MARIADB_DUMP_SKIP_DB|`"information_schema performance_schema"`|A space-separated list of databases to skip.|
46+
|MARIADB_DUMP_KEEP_DAYS|`3`|Number of database backups to keep in `MARIADB_DUMP_DIR`. This number can be low if backups are routinely performed of the system running MariaDB.|
4247

43-
- Copy `ozo-mariadb-backup.sh` to `/etc/cron.daily` and set permissions to `rwx------` (`0700`)
44-
- Copy `ozo-mariadb-backup.conf` to `/etc` and set permissions to `rw-------` (`0600`)
45-
- Modify `/etc/ozo-mariadb-backup.conf` to suit your environment:
48+
### Configure Cron
49+
Modify `/etc/cron.d/ozo-mariadb-backup` to suit your scheduling needs. The default configuration runs `ozo-mariadb-backup.sh` every day at 4:00am.
4650

47-
|Variable|Example Value|Description|
48-
|--------|-------------|-----------|
49-
|MARIADB_DUMP_USER|`"mysql-backup"`|The user that was granted permission to dump all databases|
50-
|MARIADB_DUMP_PASS|`"****************"`|The password for the `MARIADB_DUMP_USER` user|
51-
|MARIADB_DUMP_DIR|`"/var/lib/mysql-dump"`|The output directory for compressed dump files. The script will attempt to create this directory if it does not already exist|
52-
|MARIADB_DUMP_SKIP_DB|`"information_schema performance_schema"`|A space-separated list of databases to skip|
53-
|MARIADB_DUMP_KEEP_DAYS|`3`|Number of database backups to keep in `MARIADB_DUMP_DIR`. This number can be low if backups are routinely performed of the system running MariaDB|
54-
51+
## Notes
52+
Please visit [One Zero One](https://onezeroone.dev) to learn more about my other work.

ozo-mariadb-backup

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Field Allowed values
2+
# ----- --------------
3+
# minute 0-59
4+
# hour 0-23
5+
# day of month 1-31
6+
# month 1-12
7+
# day of week 0-7 (0,7 = Sunday)
8+
9+
00 04 * * * root /usr/sbin/ozo-mariadb-backup.sh

0 commit comments

Comments
 (0)