使用函数封装-公司自动化处理文件备份管理脚本
来源:互联网 发布:1024邀请码淘宝怎么搜 编辑:程序博客网 时间:2024/06/17 23:19
#!/bin/bash
srcPath=""
dstPath=""
ErrMsg="Yout enter the directory or file dose not exist. "
DstDirMsg="Please input destination dircetory"
SrcFilesMsg="Please input source dircetory or file."
DstFilesMsg="Delete the file or dircetory. "
DirFileMsg=""
function inputSourcePath(){
while true
do
echo $DirFileMsg
read srcPath
if [ -d $srcPath -o -f $srcPath ]; then
if [ -e $srcPath ]; then
break
fi
fi
echo "$ErrMsg"
done
}
function inputDstPath(){
while true
do
echo $DstDirMsg
read dstPath
if [ -d $dstPath -a -e $dstPath ]; then
break
fi
echo "$ErrMsg"
done
}
function copy(){
while true
do
inputSourcePath
inputDstPath
if [ $srcPath != $dstPath -a -d $srcPath ]; then
break
elif [ -f $srcPath -a `dirname $srcPath` != $dstPath ]; then
break
fi
echo "The source and destination cannot be the same! Please input again"
done
cp -a $srcPath $dstPath
echo "The files have been susscessfully copied."
}
function delete(){
inputSourcePath
echo "Proceed with removal? y"
read yn
if [ $yn == "y" ]; then
rm -rf $srcPath
echo "sussessfully delete!"
fi
}
function backup(){
inputSourcePath
inputDstPath
backName=`date -d today +%Y%m%d%H%M%S`
cd $dstPath
tar -czvf "$backName.tar.gz" $srcPath
echo "A successful backup to $dstPath/$backName.tar.gz"
}
while true
do
echo "*******************************************"
echo " 1 Copy"
echo " 2 Delete"
echo " 3 Backup"
echo " 4 Quit "
echo "*******************************************"
read op
case $op in
1)
echo "You selection is Copy"
DirFileMsg=$SrcFilesMsg
copy
read -p "Press any key to continue..."
clear
;;
2)
echo "You selection is delete"
DirFileMsg=$DstFilesMsg
delete
read -p "Press any key to continue..."
clear
;;
3)
echo "You selection is Back"
DirFileMsg=$SrcFilesMsg
backup
read -p "Press any key to continue..."
clear
;;
4)
echo "Exit..."
break
;;
*)
echo "Error! invalide selection, try again"
;;
esac
done
本文出自 “xinsz08の平行时空” 博客,请务必保留此出处http://xinsz08.blog.51cto.com/10565212/1915939
- 使用函数封装-公司自动化处理文件备份管理脚本
- linux下使用脚本自动化远程备份MySQL数据库
- 使用脚本和定时任务自动备份管理服务器
- DRBD自动化使用脚本
- 《软件自动化测试成功之道》节选11 - 常用脚本函数的封装
- 文件备份bat脚本
- 用shell脚本自动化备份数据库
- Openstack 数据库自动化备份python脚本
- 使用tar备份脚本
- 脚本军火库:使用Amazon S3服务备份指定文件
- linux中使用脚本来创建文件备份
- spool使用脚本封装
- 收藏——在C#使用SHGetFileInfo获取(管理)文件或者文件夹图标(C#封装Win32函数的一个例子)
- 自动化脚本之bat管理IP地址
- Linux系统文件备份脚本
- 自动备份dSYM文件脚本
- Python脚本-文件备份
- http访问接口自动化测试,函数封装
- 连接查询详解
- Construct a Matrix FZU
- raid5故障回放
- Vim的使用提高篇
- 生产环境下搭建 nagios+nconf+cacti+npc的整合
- 使用函数封装-公司自动化处理文件备份管理脚本
- web安全的学习路线
- 域名过期提前通知脚本
- linux 系统被入侵之后你要做什么
- puppet安装常遇见的问题
- mysql硬件优化
- MySQL常用查询语句
- 双系统引导故障排除
- 系统运维工程师面试题及参考答案