Skip to content

Script to create full/incremental backups with mariabackup. Compress with xbstream.

License

Notifications You must be signed in to change notification settings

jiangxiaobai/run-mariabackup

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

README

forked from jmfederico/run-xtrabackup.sh

Note: have tested on Ubuntu 18.04 with MariaDB 10.3

Links

Full Backup and Restore with Mariabackup

Incremental Backup and Restore with Mariabackup


Install mariabackup

sudo apt install mariadb-backup

Create a backup user

GRANT 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
30 2 * * * MYSQL_PASSWORD=YourPassword bash /data/script/run-mariabackup.sh > /data/script/logs/run-mariabackup.sh.out 2>&1

Restore Example

tree /data/mysql_backup/
/data/mysql_backup/
├── base
│   └── 2018-10-23_10-07-31
│       ├── backup.stream.gz
│       └── xtrabackup_checkpoints
└── incr
    └── 2018-10-23_10-07-31
        ├── 2018-10-23_10-08-49
        │   ├── backup.stream.gz
        │   └── xtrabackup_checkpoints
        └── 2018-10-23_10-13-58
            ├── backup.stream.gz
            └── xtrabackup_checkpoints
# decompress
cd /data/mysql_backup/
for i in $(find . -name backup.stream.gz | grep '2018-10-23_10-07-31' | xargs dirname); \
do \
mkdir -p $i/backup; \
zcat $i/backup.stream.gz | mbstream -x -C $i/backup/; \
done

# prepare
mariabackup --prepare --target-dir base/2018-10-23_10-07-31/backup/ --user backup --password "YourPassword" --apply-log-only
mariabackup --prepare --target-dir base/2018-10-23_10-07-31/backup/ --user backup --password "YourPassword" --apply-log-only --incremental-dir incr/2018-10-23_10-07-31/2018-10-23_10-08-49/backup/
mariabackup --prepare --target-dir base/2018-10-23_10-07-31/backup/ --user backup --password "YourPassword" --apply-log-only --incremental-dir incr/2018-10-23_10-07-31/2018-10-23_10-13-58/backup/

# stop mairadb
service mariadb stop

# empty datadir
mv /data/mysql/ /data/mysql_bak/

# copy-back
mariabackup --copy-back --target-dir base/2018-10-23_10-07-31/backup/ --user backup --password "YourPassword" --datadir /data/mysql/

# fix privileges
chown -R mysql:mysql /data/mysql/

# start mariadb
service mariadb start

# done!

About

Script to create full/incremental backups with mariabackup. Compress with xbstream.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%