ubuntu怎么样实现这样的备份功能 呢?

sh/bash/dash/ksh/zsh等Shell脚本
回复
aq6100
帖子: 11
注册时间: 2007-08-21 15:09
联系:

ubuntu怎么样实现这样的备份功能 呢?

#1

帖子 aq6100 » 2009-08-11 18:33

各位好,请问一下,我有一台Ubuntu的服务器,需要每天备份服务器上的web目录,请问怎么样才能实现,按日期建立文件夹进行备份,但是有点特别我需要循环备份,例如我只需要保留7天的备份文件,第8天的话,会把最前一天的备份放到一个准备删除的目录等候删除,应该怎么样写shell呢?
头像
O_O_BOT
帖子: 2461
注册时间: 2009-05-20 19:32

Re: ubuntu怎么样实现这样的备份功能 呢?

#2

帖子 O_O_BOT » 2009-08-12 6:40

代码: 全选

#!/bin/bash
cd /xxxx

mark_date=($(date +%Y_%m_%d -d '7 day ago'))
for dir in *_*_*;do
    [[ $dir == "*_*_*" ]] && break
    if [[ "$dir" =< "$mark_date" ]];then
        mv "$dir" /yyy
    fi
done

bdir=`date +%Y_%m_%d`
[ ! -d "$bdir" ] && mkdir "$bdir" 
cd "$bdir"
if [ ! -f "ok.log" ]; then
    #tar yourfile
    #sync
    echo "backup ok! `date +%Y_%m_%d_%H_%M`" > ok.log
fi
irc 聊天室
ubuntu-cn 的irc 频道为
irc.ubuntu.com 8001 #ubuntu-cn
UTF8编码 可用 irssi xchat pidgin weechat 登录

http://webchat.freenode.net/?channels=ubuntu-cn
[url]irc://irc.freenode.net/ubuntu-cn[/url]
头像
O_O_BOT
帖子: 2461
注册时间: 2009-05-20 19:32

Re: ubuntu怎么样实现这样的备份功能 呢?

#3

帖子 O_O_BOT » 2009-08-12 6:47

find -maxdepth 1 -name \*_\*_\* -type d -mtime 7 -exec mv {} ../yyyy \;
fifind -maxdepth 1 -name "*_*_*" -type d -mtime 7 -exec mv {} ../yyyy \;
上次由 O_O_BOT 在 2009-08-13 12:21,总共编辑 3 次。
irc 聊天室
ubuntu-cn 的irc 频道为
irc.ubuntu.com 8001 #ubuntu-cn
UTF8编码 可用 irssi xchat pidgin weechat 登录

http://webchat.freenode.net/?channels=ubuntu-cn
[url]irc://irc.freenode.net/ubuntu-cn[/url]
aq6100
帖子: 11
注册时间: 2007-08-21 15:09
联系:

Re: ubuntu怎么样实现这样的备份功能 呢?

#4

帖子 aq6100 » 2009-08-13 11:31

谢谢楼上的啦,非常感谢!
回复