#!/bin/sh
export LANG=C
DATE=`date '+%Y%m%d_%H%M'`
GENERATION=2
BACKUP_PATH='/path/to/backup/dir/'
ARCHIVE_TARGET_DIR='/path/to/target/dir'
ARCHIVED_FILE_NAME=${ARCHIVE_TARGET_DIR##*/}_${DATE}.tar.gz
archive() {
echo "archive ${ARCHIVE_TARGET_DIR}"
tar zcf /tmp/${ARCHIVED_FILE_NAME} ${ARCHIVE_TARGET_DIR}
}
delete_old_backup() {
num=`ls -t ${BACKUP_PATH}${ARCHIVE_TARGET_DIR##*/}_*.tar.gz | wc -l`
num=`expr ${num} - ${GENERATION}`
if [ ${num} -gt 0 ]
then
echo "deleting ${num} files..."
for file in `ls -t ${BACKUP_PATH}${ARCHIVE_TARGET_DIR##*/}_*.tar.gz | tail -${num}`
do
rm -f ${file}
done
fi
}
if archive
then
mv /tmp/${ARCHIVED_FILE_NAME} ${BACKUP_PATH}
delete_old_backup
echo 'backup successful!'
fi
2009年10月6日火曜日
backup shell script
投稿者 takabow 投稿日時 10/06/2009
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿