Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8207e6a
Make defaults the same as in bgbackujp
michaeldg Dec 15, 2017
a7202e5
If bgbackup is called bgbackup.sh, so should bgrestore be called.
michaeldg Oct 30, 2019
ab63305
First attempt to support mariabackup for restores
michaeldg Apr 1, 2020
71b0eed
Oops, backuptool 1 = mariadb
michaeldg Apr 1, 2020
9fdce0d
Implemented skipcopy and bugfixes
michaeldg Apr 7, 2020
3e18507
FIxed typo
michaeldg Apr 7, 2020
03044bf
Bugfix in combination with skipcopy
michaeldg Apr 8, 2020
b7bf99b
Fixe typo
michaeldg Apr 8, 2020
dbcbf4a
Fixed another typo
michaeldg Apr 8, 2020
6428f72
Added some defensiveness in shutting down MariaDB, added some newlines
michaeldg May 12, 2020
9fe2965
Made bgrestore compatible with MySQL 5.7 compatibility changes I made in
michaeldg Aug 6, 2020
2720c8a
Changed copy-back to move-back to save disk space on big installations
michaeldg Aug 20, 2020
8346596
Fixed syntax
michaeldg Sep 28, 2021
0a3948e
Re-enabled encrytion support
michaeldg Nov 30, 2021
c7aa555
Add feature to delete old restore first.
michaeldg Apr 5, 2024
a83333c
Made decrypting and decomprsssing defensive
michaeldg Apr 5, 2024
add4bd4
Fixed bug and made defensive
michaeldg Apr 5, 2024
e15c368
Oops....
michaeldg Apr 5, 2024
b23e8fe
Add defensiveness
michaeldg Jul 2, 2024
3b08a99
Corrected move back command
michaeldg Jul 2, 2024
294acdc
Add log cleanup
michaeldg Jul 31, 2024
8a6122b
Fix deleting of log files
michaeldg Jul 31, 2024
b38d306
Remove bktype feature
michaeldg May 13, 2025
7e169fb
Fix chmod
michaeldg Jul 24, 2025
996be61
Add author
michaeldg Sep 27, 2025
9637efc
Add work-around for MDEV-6660
michaeldg Sep 29, 2025
725cc9d
Delegate the actual restore to fgrestore, add multi-instance support
michaeldg Aug 19, 2026
df8f72c
Restore the latest backup of any type, not just the latest Full
michaeldg Aug 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# bgrestore

bgrestore-auto.sh helps you automatically restore the last successful backup from bgbackup to another MariaDB server. This is very useful for verifying backups, refreshing development environments, etc.

bgrestore connects to the backup_history table in mdbutil to gather information about the last successful full backup such as whether it's encrypted, compressed, etc. This information is then used to restore on the designated MariaDB server.
bgrestore.sh helps you automatically restore the last successful full backup from bgbackup to another MariaDB server. This is very useful for verifying backups, refreshing development environments, etc.

bgrestore connects to the backup_history table in mdbutil to find the last successful full backup for a given host. It then delegates the actual restore (decrypt, decompress, prepare, move-back) to [fgrestore](../mysql-mariadb-physical-backup/files/fgrestore.sh), which needs to be installed alongside bgrestore on the restore host. bgrestore itself only keeps what's genuinely its own: the backup_history lookup, logging/mail, and stopping/starting the MariaDB service around the restore.

## How to...

This all assumes the backup was taken with bgbackup (https://github.com/bstillman/bgbackup). This is necessary for the script to gather the required information.
This all assumes the backup was taken with bgbackup (https://github.com/bstillman/bgbackup). This is necessary for the script to gather the required information.

Copy bgrestore.cnf.dist to /etc/bgrestore.cnf and configure as needed (details below).
Copy bgrestore.cnf.dist to /etc/bgrestore.cnf and configure as needed (details below). To run restore tests against a multi-instance host, copy it to a distinct path per instance instead and select it with `bgrestore -c /path/to/that/instance's/bgrestore.cnf`.

Currently the script assumes the location of the backup on the source and the destination is the same. Ex: if the backup is in /backups on the server backed up, it should also reside in /backups on the server to be restored.

Expand Down Expand Up @@ -70,13 +69,13 @@ The hostname of the server from which the backup was taken. Ex. If backing up se

The full path to the data directory on the MariaDB server to be restored.

### datadirowner
### restore_my_cnf_file

The owner of the data directory. Usually mysql.
The my.cnf fgrestore should use for the restore. Parses datadir, tmpdir, innodb log/doublewrite dirs, log-error/log-bin/relay-log paths, and the owning `user=` (fgrestore chowns restored files to whatever `user=` says there, default mysql, if it's not set).

### datadirgroup
### service_name

The group of the data directory. Usually mysql.
The systemd service name to stop/start around the restore. Defaults to `mariadb`; set per-instance (via a distinct config file selected with `-c`) to run restore tests against a multi-instance host.

### logpath

Expand Down
222 changes: 0 additions & 222 deletions bgrestore-auto.sh

This file was deleted.

29 changes: 19 additions & 10 deletions bgrestore.cnf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@

# bgrestore configuration file

# Path to the my.cnf fgrestore should use for the restore (parses datadir, tmpdir,
# innodb log/doublewrite dirs, log-error/log-bin/relay-log paths, and the owning
# 'user=' for chown). Same default fgrestore itself falls back to.
restore_my_cnf_file=/etc/my.cnf

# systemd service name to stop/start around the restore. Needed to target a specific
# instance when running restore tests on a multi-instance host; select which
# bgrestore.cnf (and thus which service_name) via '-c|--config'.
service_name=mariadb

# MariaDB host for restore
restorehost=127.0.0.1
restorehost=localhost

# MariaDB port for restore
restoreport=40001
restoreport=3306

# MariaDB user for restore
restoreuser=bgbackup
Expand All @@ -19,10 +28,10 @@ restorepass=password
preppath=/backup/tmp

# MariaDB host for backup history
backuphisthost=127.0.0.1
backuphisthost=localhost

# MariaDB port for backup history
backuphistport=40002
backuphistport=3306

# MariaDB user for backup history
backuphistuser=bgbackup
Expand All @@ -36,18 +45,18 @@ backuphistschema=mdbutil
# MariaDB host which backup should be from
backuphost=hostname_from_backup_history

# Skip copy step, place backup in preppath after creating it. This will also make bgrestore delete the contents of the folder instead of the folder itself (after succeeding)
skipcopy=no

# Datadir
datadir=/var/lib/mysql

# Datadir owner
datadirowner=mysql

# Datadir group
datadirgroup=mysql

# Path to keep logs
logpath=/var/log

# Number of logs to keep
keeplognum=1000

# Log to syslog
syslog=no

Expand Down
Loading