Skip to content

A script that creates full/incremental backups compressed with xbstream using mariabackup . Made for CentOS 7.

License

Notifications You must be signed in to change notification settings

shunkica/run-mariabackup

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 

Repository files navigation

README

forked from omegazeng/run-mariabackup.sh which was forked from jmfederico/run-xtrabackup.sh

Note: tested on CentOS 7 with MariaDB 10.4

Links

Full Backup and Restore with Mariabackup

Incremental Backup and Restore with Mariabackup


Install

yum -y install MariaDB-backup
curl https://raw.githubusercontent.com/shunkica/run-mariabackup/master/run-mariabackup.sh --output /usr/local/sbin/run-mariabackup.sh
chmod 700 /usr/local/sbin/run-mariabackup.sh

Create a backup user

GRANT PROCESS, RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'backup'@'localhost' identified by 'YourPassword';
FLUSH PRIVILEGES;

Usage

MYSQL_PASSWORD=YourPassword bash run-mariabackup.sh

Crontab

#MySQL Backup, run every hour at the 30th minute
30 */1 * * * MYSQL_PASSWORD=YourPassword /bin/bash /usr/local/sbin/run-mariabackup.sh

Restore Example

The script for restoring data from backups is intentionally left out, but here is an example of how you might do it.

# tree /home/mysqlbackup/
/home/mysqlbackup/
├── base
│   └── 2020-03-12_12-08-44
│       ├── backup.stream.gz
│       ├── xtrabackup_checkpoints
│       └── xtrabackup_info
└── incr
    └── 2020-03-12_12-08-44
        ├── 2020-03-12_13-24-20
        │   ├── backup.stream.gz
        │   ├── xtrabackup_checkpoints
        │   └── xtrabackup_info
        └── 2020-03-12_13-54-25
            ├── backup.stream.gz
            ├── xtrabackup_checkpoints
            └── xtrabackup_info
# decompress
cd /home/mysqlbackup/
for i in $(find . -name backup.stream.gz | grep '2020-03-12_12-08-44' | xargs dirname); \
do \
mkdir -p $i/backup; \
zcat $i/backup.stream.gz | mbstream -x -C $i/backup/; \
done

# prepare
mariabackup --prepare --target-dir base/2020-03-12_12-08-44/backup/ --user backup --password "YourPassword"
mariabackup --prepare --target-dir base/2020-03-12_12-08-44/backup/ --user backup --password "YourPassword" --incremental-dir incr/2020-03-12_12-08-44/2020-03-12_13-24-20/backup/
mariabackup --prepare --target-dir base/2020-03-12_12-08-44/backup/ --user backup --password "YourPassword" --incremental-dir incr/2020-03-12_12-08-44/2020-03-12_13-54-25/backup/

# stop mariadb
systemctl stop mariadb

# move datadir
mv /var/lib/mysql/ /var/lib/mysql_bak/

# copy-back
mariabackup --copy-back --target-dir base/2020-03-12_12-08-44/backup/ --user backup --password "YourPassword" --datadir /var/lib/mysql/

# fix privileges
chown -R mysql:mysql /var/lib/mysql/

# fix selinux context
restorecon -Rv /var/lib/mysql

# start mariadb
systemctl start mariadb

# done!

About

A script that creates full/incremental backups compressed with xbstream using mariabackup . Made for CentOS 7.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%