使用函数封装-公司自动化处理文件备份管理脚本
2017-04-14 13:39
543 查看
#!/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
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
相关文章推荐
- 使用函数封装-公司自动化处理文件备份管理脚本
- 批处理脚本实现自动备份站点文件到远程,使用zip package更新站点
- 使用T-SQL进行数据库备份并检查该备份文件是否存在且作出相应处理
- 自动化备份远程服务器端的文件到本地的Shell脚本
- mysql定期备份数据并压缩上传到ftp服务器的bat文件脚本,恢复建议使用SQLyog enterprise
- CentOS中使用Shell脚本实现每天自动备份网站文件和数据库并上传到FTP中(转)
- CentOS中使用Shell脚本实现每天自动备份网站文件和数据库并上传到FTP中
- 使用T-SQL进行数据库备份并检查该备份文件是否存在且作出相应处理
- 使用bat批处理方式定期备份和定期删除oracle备份文件
- python使用7z解压软件备份文件脚本分享
- 使用RMAN和控制文件备份删除归档日志的SHELL脚本--RED HAT 5 LINUX 64
- Selenium webdriver 使用python脚本处理SWFupload 文件上传
- 使用 Perl 脚本实现交互式命令行程序的管理与测试自动化
- 使用perl脚本语言处理文本文件
- 数据库管理——Powershell——使用Powershell脚本找出消耗最多磁盘空间的文件
- 《使用shell位置变量进行目录文件的备份小脚本》
- 使用 Perl 脚本实现交互式命令行程序的管理与测试自动化
- 数据库管理——Powershell——使用Powershell脚本找出消耗最多磁盘空间的文件
- Python笔记–IAR使用Python脚本实现自动对烧录文件进行处理
- Centos 使用sed在脚本中处理文件