Skip to content

Shell script to create full/incremental backups with mariabackup

License

Notifications You must be signed in to change notification settings

uw-asa/mariabackup.sh

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mariabackup.sh

Shell script to create full/incremental backups with mariabackup

This fork has been modified to stream backups to an Azure blob storage container. Requires azcopy.

Backup

> ./mariabackup.sh backup -h

Usage: mariabackup.sh [options] backup [<args>]

Create full/incremental backups with mariabackup

args:
  --full                  full backup
  --incr                  incremental backup (on top of most recent full backup)

options:
  -h, --help              show this help message and exit
  -v, --version           show program's version number and exit
  -d, --debug             show debug messages
  --loglevel LOGLEVEL, -l LOGLEVEL
                          level of log messages to capture (one of debug, info, warn, error). Default:
                          info
  mariadb connection options
  --host                  mysql hostname. Default:
                              'MYSQL_HOST' env variable used by default, 'localhost' used if not set
  --port                  mysql port. Default:
                              'MYSQL_PORT' env variable used by default, '3306' used if not set
  --user                  mysql user. Default:
                              'MYSQL_USER' env variable used by default, 'root' used if not set
  --password              mysql password. Default: 'MYSQL_PASSWORD' env variable

Create backup user

-- See https://mariadb.com/kb/en/mariabackup-overview/#authentication-and-privileges
CREATE USER 'backup'@'%' IDENTIFIED BY 'YourPassword';

-- MariaDB < 10.5:
GRANT RELOAD, PROCESS, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'backup'@'%';
-- MariaDB >= 10.5:
GRANT RELOAD, PROCESS, LOCK TABLES, BINLOG MONITOR ON *.* TO 'backup'@'%';

FLUSH PRIVILEGES;

Backup folder structure

/backup/
├── <full_1>/
│   ├── backup.mb.xz
│   ├── xtrabackup_checkpoints
│   ├── xtrabackup_info
│   ├── <incr_1>/
│   │   └── backup.mb.xz
│   .
│   └── <incr_n>/
│       └── backup.mb.xz
.
└── <full_n>/

The backup folder names have the following format:

<year>-<month>-<day>_<hour>-<minute>-<second>

Restore

>./mariabackup.sh restore -h
Usage: mariabackup.sh [options] restore [<args>]

Restore a backup with mariabackup

args:
  --name                  backup name. Default: the most recent one if not specified

options:
  -h, --help              show this help message and exit
  -v, --version           show program's version number and exit
  -d, --debug             show debug messages
  --loglevel LOGLEVEL, -l LOGLEVEL
                          level of log messages to capture (one of debug, info, warn, error). Default:
                          info
  mariadb connection options
  --host                  mysql hostname. Default:
                              'MYSQL_HOST' env variable used by default, 'localhost' used if not set
  --port                  mysql port. Default:
                              'MYSQL_PORT' env variable used by default, '3306' used if not set
  --user                  mysql user. Default:
                              'MYSQL_USER' env variable used by default, 'root' used if not set
  --password              mysql password. Default: 'MYSQL_PASSWORD' env variable

Environment variable configuration

  • AZCOPY_CONTAINER_URL: The URL for the destination container, without SAS token
  • AZCOPY_SAS_TOKEN: The SAS token part of the destination container URL, beginning with "?"
  • MYSQL_HOST:
  • MYSQL_PORT:
  • MYSQL_USER:
  • MYSQL_PASSWORD:
  • MYSQL_BACKUP_ROOT: backup root path, default: /backup
  • MYSQL_BACKUP_THREADS: number of threads to use for parallel data file transfer
  • MYSQL_BACKUP_STREAM: whether to enable streaming backup to remote storage
  • MYSQL_BACKUP_KEEP_DAYS: maximum age of full backups
  • MYSQL_BACKUP_KEEP_N: maximum number of full backups
  • MYSQL_BACKUP_LOG_LEVEL: log level, one of debug, info, warn, error

About

Shell script to create full/incremental backups with mariabackup

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%