서버 백업(삭제) 시스템 (크론)
서버 백업 시스템 (크론)
[root@web tmp]# vi /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
# backup
0 06 * * * root /root/backup.sh
[root@web tmp]# vi ~/backup.sh
#!/bin/bash
tar cvfz /tmp/superbak.tar.gz /home
#scp /tmp/superbak.tar.gz root@111.122.122.122:/home/
cat /dev/null > /usr/local/apache/logs/error_log
mysqldump --lock-all-tables super > /tmp/super_DB.sql
scp /tmp/super_DB.sql root@111.122.122.122:/home/
#7일 지난 백업 파일 삭제
#find [디렉토리] [옵션] -exec rm {} \;
# 매일 새벽 2시 삭제 크론탭 등록
00 02 * * * find /mysql_backup/ -type f -name '*.tar.gz' -mtime +7 -exec rm {} \;