|
1 | | -# OZO MariaDB Backup |
| 1 | +# OZO MariaDB Backup Installation and Configuration |
2 | 2 |
|
3 | 3 | ## 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. |
5 | 5 |
|
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 '****************'.) |
13 | 8 |
|
| 9 | +### AlmaLinux, Red Hat Enterprise Linux, Rocky Linux |
14 | 10 | ``` |
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; |
22 | 18 | ``` |
| 19 | +### Debian |
| 20 | +PENDING. |
23 | 21 |
|
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. |
25 | 24 |
|
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 |
28 | 31 | ``` |
29 | 32 |
|
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. |
38 | 35 |
|
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. |
40 | 39 |
|
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.| |
42 | 47 |
|
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. |
46 | 50 |
|
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. |
0 commit comments