티스토리 뷰
root@api:/usr/local/apache-tomcat-7.0.64# cat ~/mysql-backup.sh
#!/bin/bash backupdir='/home/freecatz/MYSQL_BACKUP/'`date +%Y%m%d` olddir='/home/freecatz/MYSQL_BACKUP/'`date -d "7 day ago" +%Y%m%d` function FN_DB_BACKUP(){ echo $(date +%H:%M) - $1 DATABASE FULL BACKUP START. >> $backupdir/$1.log mysqldump -uroot -p'qwer1234' $1 > $backupdir/$1.sql echo $(date +%H:%M) - $1 DATABASE FULL BACKUP FINISH. >> $backupdir/$1.log mysql -uroot -p'qwer1234' -e "SELECT TABLE_SCHEMA, CONCAT(FORMAT(SUM(DATA_LENGTH + INDEX_LENGTH) / (1024*1024), 2), 'MB') FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '$1'" | grep -v TABLE_SCHEMA >> $backupdir/$1.log } function FN_MK_DIR(){ mkdir -p $backupdir if [ -d $olddir ]; then rm -rf $olddir fi } if [ ! -d $backupdir ]; then FN_MK_DIR fi FN_DB_BACKUP DBTEST1 FN_DB_BACKUP DBTEST2 FN_DB_BACKUP DBTEST3
crontab 에 주기적으로 실행 시켜 두면 된다.
# /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) 00 23 * * * root /root/mysql-backup.sh #
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 엘리스센터
- place
- SSL
- food
- Security
- kotlin
- Spring
- Java
- dart
- 맛집
- web
- HTTP
- Compile
- Review
- ssh
- TIP
- samba
- Mobile
- Fun
- json parse
- springboot
- Flutter
- Linux
- Android
- MySQL
- JavaScript
- gpkiapi
- development
- devel
- devtools
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함