Full and incremental script along with prepare script to uncompress and apply incremental backups to full backup
Parts of the scripts are standard to Redhat/yum distros which means you may find that you need to change tools used in the script to better suit your OS. You may need to install pigz, or change it to gzip and gunzip.
- Full and incremental backups (compressed with gzip)
- Retention policy
- Email on failure (mailx)
- Auto removal of failed incremental backups
- Prepare script that loops through incremental backups to apply new changes to full backup
bash mariabackup.bash
bash prepare.bash /media/backups/dateofback
create user 'backup'@'localhost' identified by 'password';
grant reload,process,lock tables,binlog monitor,connection admin,slave monitor on *.* to 'backup'@'localhost';
# Define the backup directory
backup_dir=/media/backups/
# Define the mariadb user and password
user=backup
password=password
#emaillist, spaces in-between, no commas
emails="[email protected]"
fromemail="[email protected]"
#number of days to keep backups
#0= just today's backup | 1= today and yesterday | 2=today,yesterday,day before etc
backupdays=0
#dump table sturture per for single database restores (full innodb databases only)
dumpstructure='n'
Do not change, will break script |
---|
"--backup" |
"--user=$user" |
"--password=$password" |
"--target-dir=$fullbackuplocation" |
"--extra-lsndir=$extra_lsndir" |
"--stream=xbstream" |
You have options for full and incremental backups. Having two sets of options allows you to have lots of parallel threads for the full backup early in the morning and a few in working hours to stop the database becoming slow during the day as incremental backups shouldn't take long to complete
#----------define backup options------------
#incremental options
declare -a backup_options_inc=(
"--backup"
"--user=$user"
"--password=$password"
"--extra-lsndir=$extra_lsndir"
"--incremental-basedir=$extra_lsndir"
"--stream=xbstream"
"--slave-info"
"--parallel=1"
)
#full backup options
declare -a backup_options_full=(
"--backup"
"--user=$user"
"--password=$password"
"--target-dir=$fullbackuplocation"
"--extra-lsndir=$extra_lsndir"
"--stream=xbstream"
"--slave-info"
"--parallel=1"
)