$ vi mariadb_backup.sh
#!/bin/bash # all databases backup HOME_DIR=/mysql BACKUP_DIR=$HOME_DIR/backup TODAY=`date -d now +%Y-%m-%d` if [ -d "$BACKUP_DIR/FULL_$TODAY" ] ; then rm -rf $BACKUP_DIR/FULL_$TODAY fi mkdir -p $BACKUP_DIR/FULL_$TODAY mariabackup --backup --rsync --user=root \ --password=root5818 --target-dir=$BACKUP_DIR/FULL_$TODAY |
$ vi mariadb_increment.sh
#!/bin/bash # all databases increment backup HOME_DIR=/mysql BACKUP_DIR=$HOME_DIR/backup #TODAY=`date -d now +%Y-%m-%d` BACKUP_FILE_NUM=`ls $BACKUP_DIR | wc -l` FULL_DIR=`ls -dtr $BACKUP_DIR/FULL_* | tail -1 | cut -d '_' -f2 | cut -d ':' -f1` INCREMENT_NUM=`ls -d $BACKUP_DIR/INCR_$FULL_DIR* 2>/dev/null | wc -l` INCREMENT_DIR=$BACKUP_DIR/INCR_$FULL_DIR\_$INCREMENT_NUM if [ -d "$INCREMENT_DIR" ] ; then rm -rf $INCREMENT_DIR fi mkdir -p $INCREMENT_DIR echo $INCREMENT_DIR mariabackup --backup --rsync --user=root --password=root5818 \ --incremental-basedir=$BACKUP_DIR/FULL_$FULL_DIR --target-dir=$INCREMENT_DIR |
$ vi mariadb_dump.sh
#!/bin/bash # test database dump HOME_DIR=/mysql BACKUP_DIR=$HOME_DIR/backup DB_NAME=test TODAY=`date -d now +%Y-%m-%d` if [ -e "$BACKUP_DIR/$DB_NAME\_$TODAY\.dmp" ] ; then rm -rf $BACKUP_DIR/$DB_NAME\_$TODAY\.dmp fi mysqldump -u root -proot5818 --databases $DB_NAME > $BACKUP_DIR/$DB_NAME\_$TODAY\.dmp |
$ vi rm_backup.sh
#!/bin/bash # remove backup HOME_DIR=/mysql BACKUP_DIR=$HOME_DIR/backup DATE_FOR=`date -d '4 weeks ago' '+%Y%m%d'` BACKUP_LIST=`ls -d $BACKUP_DIR/* |cut -d '_' -f2 | cut -d '.' -f1 | tr -d '-'` for d in $BACKUP_LIST do if [ $DATE_FOR -ge $d ] ; then $REMOVE_DATE=$(d:0:4)-$(d:4:2)-$(d:6:2) rm -rf $BACKUP_DIR/*$REMOVE_DATE* fi done |
'Mariadb' 카테고리의 다른 글
[Mariadb] 쿼리 캐시 분석 및 튜닝하는 방법 (0) | 2021.04.01 |
---|