Shell command to tar directory excluding certain files/folders

后端 未结 28 2283
春和景丽
春和景丽 2020-11-27 08:31

Is there a simple shell command/script that supports excluding certain files/folders from being archived?

I have a directory that need to be archived with a sub dire

28条回答
  •  旧时难觅i
    2020-11-27 09:24

    Success Case: 1) if giving full path to take backup, in exclude also should be used full path.

    tar -zcvf /opt/ABC/BKP_27032020/backup_27032020.tar.gz --exclude='/opt/ABC/csv/' --exclude='/opt/ABC/log/' /opt/ABC

    2) if giving current path to take backup, in exclude also should be used current path only.

    tar -zcvf backup_27032020.tar.gz --exclude='ABC/csv/' --exclude='ABC/log/' ABC

    Failure Case:

    1. if giving currentpath directory to take backup and full path to ignore,then wont work

      tar -zcvf /opt/ABC/BKP_27032020/backup_27032020.tar.gz --exclude='/opt/ABC/csv/' --exclude='/opt/ABC/log/' ABC

    Note: mentioning exclude before/after backup directory is fine.

提交回复
热议问题