免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1740 | 回复: 0
打印 上一主题 下一主题

备份的shell [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-10-22 16:50 |只看该作者 |倒序浏览

#!/bin/sh
#
# Copyright (C) 2007 Edwin Y.X. Zeng
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
#
# See http://www.gnu.org/licenses/gpl.html for the complete text of license.
#
# $Id: backhome.sh,v 1.2 2007-10-17 16:43:20 zyangxue Exp $
# FileName: backhome.sh
# Version: $Revision: 1.2 $
# Discription:
# 1. Auto backup the home directory by tar
# 2. Backup files named username-YYYY-MM-DD.tar.gz
# 3. delete the oldest backup files.
#
# The user's name
user_name=edwin
user_home=$(finger ${user_name} | awk '/^Directory/{print $2}')
# Generate the tar.gz file name for this times
# curdate=$(date | awk '{print $6"-"$2"-"$3}')
curdate=$(date +%F)
curfl=${user_name}"-"${curdate}
# Where is the tar.gz stored into
bkdir=/media/sda5/cvs
# How many tar.gz reserved
bknum=5
cd ${user_home}
rm -rf .macromedia .viminfo .bash_history .dmrc .mplayer .gqview \
       .thumbnails .xsession-errors .xscreansaver .hxplayerrc \
       .sudo_as_admin_successful .maple .lesshst .recently-use* \
       Signature/enig*.txt
cd ${bkdir}
if [ ! -e ${curfl}.tar.gz ]; then
    echo "Press CTRL-C to interrupt......"
    trap 'rm -f ${curfl}.tar.gz' INT
    echo "Backing files......"
    tar zcvf ${curfl}.tar.gz ${user_home}/.[a-zA-z0-9]* ${user_home}/*
else
    echo "Because of conflict with exist files, skipping ...."
    exit 0
fi
gznum=$(ls -lt ${user_name}-20[0-2][0-9]-[01][0-9]-[0-3][0-9].tar.gz | wc -l)
if [ ${gznum} -gt ${bknum} ]; then
    bkarches=$(ls -lt ${user_name}-20[0-2][0-9]-[01][0-9]-[0-3][0-9].tar.gz | \
                awk -v mrnum=${bknum} '{if (NR > mrnum) {print $8} }')
    for todel in ${bkarches}; do
        echo deleting ${todel}...
        rm -f ${todel}
    done
fi


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/51573/showart_405324.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP