如何使用shell脚本从备份中删除多余的文件?
备份 Shell 脚本
#!/bin/bash
backdest=/home/backup
date=$(date "+%F")
backupall="$backdest/arch-full-$date.tgz"
backuphome="$backdest/jary_p-$date.tgz"
tar -czpvf $backupall / --exclude=/home/* --exclude=/mnt/* --exclude=/media/* \
--exclude=/proc/* --exclude=/sys/* --exclude=/dev/* \
--exclude=/tmp/* --exclude=/lost+found/*
tar -czpvf $backuphome /home/jary_p
数(5)次后
/home/backup 中有 Serveral(10) 个文件
$ls /home/backup
backup.sh
arch-full-2011-05-13.tgz
arch-full-2011-05-25.tgz
arch-full-2011-06-01.tgz
arch-full-2011-06-09.tgz
arch-full-2011-06-11.tgz
jary_p-2011-05-13.tgz
jary_p-2011-05-25.tgz
jary_p-2011-06-01.tgz
jary_p-2011-06-09.tgz
jary_p-2011-06-11.tgz
我怎样才能保留最新的 3 个文件(6) 并删除多余的文件?
谢谢
并且,抱歉我糟糕的英语。
A backup Shell Script
#!/bin/bash
backdest=/home/backup
date=$(date "+%F")
backupall="$backdest/arch-full-$date.tgz"
backuphome="$backdest/jary_p-$date.tgz"
tar -czpvf $backupall / --exclude=/home/* --exclude=/mnt/* --exclude=/media/* \
--exclude=/proc/* --exclude=/sys/* --exclude=/dev/* \
--exclude=/tmp/* --exclude=/lost+found/*
tar -czpvf $backuphome /home/jary_p
Several(5) times later
there are Serveral(10) files in /home/backup
$ls /home/backup
backup.sh
arch-full-2011-05-13.tgz
arch-full-2011-05-25.tgz
arch-full-2011-06-01.tgz
arch-full-2011-06-09.tgz
arch-full-2011-06-11.tgz
jary_p-2011-05-13.tgz
jary_p-2011-05-25.tgz
jary_p-2011-06-01.tgz
jary_p-2011-06-09.tgz
jary_p-2011-06-11.tgz
How can I just keep the lastest 3 fiels(6) and delete extra files?
thanks
and, apologize my poor English.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
并使用 $backupall 的 glob 重复
And repeat with $backupall's glob
我已经找到如何解决它
I have found how to solved it