Linux命令行与shell脚本(20)--实例:备份文件

来源:互联网 发布:手机映射软件 编辑:程序博客网 时间:2024/06/07 00:04
  • 创建一个配置文件,该文件包含了要备份的每个目录或文件
$ cat files_backup_config /Users/chenhong/Desktop/shell_workspace/mysql.sh/Users/chenhong/Desktop/shell_workspace/disk_used_view.sh/Users/chenhong/Desktop/shell_workspace/file.sh
  • 编写脚本
#!/bin/bashdate=`date +%y%m%d`file=filebackup$date.tar.gzconfig_file=`pwd`/files_backup_config;destination=`pwd`/$file;if [ -f $config_file ]then    echo "load $config_file";else    echo "Sorry,can not find config file $config_file";    exit 1;fifile_number=0;exec < $config_file;read file_name;while [ $? -eq 0 ]  # read命令执行结果为0do    if [ -f $file_name -o -d $file_name ] #-o 表示or    then        file_list="$file_list "$file_name;    else        echo "$file_name does not exist";        echo "the number is $file_number";    fi    file_number=$[ $file_number + 1 ];    read file_name;donetar -czf $destination $file_list 
0 0
原创粉丝点击