【问题标题】:Bash script to backup modified file in a particular folder structure用于在特定文件夹结构中备份修改文件的 Bash 脚本
【发布时间】:2016-03-10 16:16:10
【问题描述】:

我有一个文件夹结构,我正在备份修改过的文件 下面是文件夹结构

/home/aaditya/customer/jiva/foo/bar/File1.txt

使用下面的命令我想备份 File1.txt 文件

 cd /home/aaditya/customer/jiva/foo/bar
 tar -zcvf archive_backup_folder.tar.gz File1.txt

但我的问题是,当我解压缩 tar archive_backup_folder 时,File1.txt 应该在 customer/jiva/foo/bar/File1.txt 中,而不仅仅是 File1.txt
任何人都可以帮助我如何做到这一点。

【问题讨论】:

    标签: linux bash


    【解决方案1】:

    只要做:

    cd /home/aaditya/
    tar -zcvf archive_backup_folder.tar.gz customer/jiva/foo/bar/File1.txt
    

    即在存档中包含路径结构。

    【讨论】:

    • 嗨 Kaylum,感谢您的回复,但我不想将文件夹结构硬编码,我给出了简单的示例,但实际上从 /home/aaditya 我正在导航每个文件夹或子文件夹以查找任何修改文件是否存在我正在备份文件
    【解决方案2】:

    你可以试试这样的

    TIME=`date +%b-%d-%y`
    FILENAME=backup-$TIME.tar.gz
    SRCDIR= directory or file that has to be backed up
    DESDIR= place where you need to store it
    tar -cpzf $DESDIR/$FILENAME $SRCDIR
    

    【讨论】:

      【解决方案3】:
       cd /home/aaditya/
       find customer -mtime -1 -exec tar -rvf test.tar {} \;
      

      “find”命令将找出在 1 天内修改的所有文件,并为每个文件运行“tar -rvf test.tar the_file”将其添加到 test.tar(您希望“rm -f test运行“查找”命令之前的 .tar"

      【讨论】:

        猜你喜欢
        • 2014-07-23
        • 2021-11-03
        • 2012-01-06
        • 2014-09-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多