쉘 프로그래밍
description : 쉘 프로그래밍 예정
author : 주레피
email : dhan@repia.com
lastupdate : 2022-03-10
Case Study
백업 스크립트
#!/bin/sh
cd /volume1/dhan/synology/
date >> backup.log
WIKI_BACKUP_SOURCE=/volume1/web/dokuwiki/data/media/wiki/backup
WIKI_BACKUP_TARGET="/volume1/homes/[resources]/rwiki backup"
YESTERDAY=`date -d '1 day ago' +%Y%m%d`
#1. 백업데이터 이동
echo "${WIKI_BACKUP_SOURCE}/dw-backup-${YESTERDAY}*.tar ${WIKI_BACKUP_TARGET}" >> backup.log
mv "${WIKI_BACKUP_SOURCE}"/dw-backup-"${YESTERDAY}"-*.tar "${WIKI_BACKUP_TARGET}"
#2. 180일 이전 데이터 삭제
echo "find ${WIKI_BACKUP_TARGET} -name dw*tar -mtime +180 -exec rm -f {} \;" >> backup.log
find "${WIKI_BACKUP_TARGET}" -name dw*tar -mtime +180 -exec rm -f {} \;
#find "${WIKI_BACKUP_TARGET}" -name dw*tar -mtime +180 -ls
Example