不使用根文件夹进行压缩



我的问题是,我必须使用linux zip控制台命令生成一个zip文件。我的命令如下:

zip -r /folder1/folder2/EXP_45.zip /folder1/folder2/EXP_45/

这只返回一个正确的zip,其中包括我想要的根文件夹:

返回

EXP_45.zip

-折页1

--折页2

---EXP_45

我想要

EXP_45.zip

-EXP_45

EXP_45是一个可以包含文件和文件夹的文件夹,它们必须存在于zip中。我只想让树结构从EXP_45文件夹开始。

有什么解决办法吗?

我之所以需要它是一个单独的命令,是因为它是PLSQL函数中作业的一个操作,比如:

BEGIN
DBMS_SCHEDULER.CREATE_JOB ( 
JOB_NAME=>'compress_files',       --- job name 
JOB_ACTION=>'/usr/bin/zip',    --- executable file with path 
JOB_TYPE=>'executable',        -----   job type
NUMBER_OF_ARGUMENTS=>4,  --  parameters in numbers                   
AUTO_DROP =>false,
CREDENTIAL_NAME=>'credentials'   -- give credentials name which you have created before "credintial"
);
dbms_scheduler.set_job_argument_value('compress_files',1,'-r');
dbms_scheduler.set_job_argument_value('compress_files',2,'-m');
dbms_scheduler.set_job_argument_value('compress_files',3,'/folder1/folder2/EXP_45.zip');
dbms_scheduler.set_job_argument_value('compress_files',4,'/folder1/folder2/EXP_45/');
DBMS_SCHEDULER.RUN_JOB('compress_files');
END;

我还没能用zip找到这个问题的解决方案,但我用jar找到了。命令是:

jar cMf /folder1/folder2/EXP_45.zip -C /folder1/folder2/EXP_45 .

此外,在pl-sql中使用作业的解决方案是:

BEGIN
DBMS_SCHEDULER.CREATE_JOB ( 
JOB_NAME=>'compress_files',       --- job name 
JOB_ACTION=>'/usr/bin/jar',    --- executable file with path 
JOB_TYPE=>'executable',        -----   job type
NUMBER_OF_ARGUMENTS=>5,  --  parameters in numbers                   
AUTO_DROP =>false,
CREDENTIAL_NAME=>'credentials'   -- give credentials name which you have created before "credintial"
);
dbms_scheduler.set_job_argument_value('compress_files',1,'cMf');
dbms_scheduler.set_job_argument_value('compress_files',2,'/folder1/folder2/EXP_45.zip');
dbms_scheduler.set_job_argument_value('compress_files',3,'-C');
dbms_scheduler.set_job_argument_value('compress_files',4,'/folder1/folder2/EXP_45');
dbms_scheduler.set_job_argument_value('compress_files',5,'.');
DBMS_SCHEDULER.RUN_JOB('compress_files');
END;

创建zip文件时,您希望使用-j(或--junk-paths(选项。以下是zip手册页。

-j
--junk-paths
Store just the name of a saved file (junk the path), and do not store directory names. 
By default, zip will store the full path (relative to the current directory).

更新以下问题澄清

为什么不把下面的代码放在shell脚本中;让SQL函数来调用它?您只需要将目录名传递给cd into和输出zip的名称。

cd folder1/folder2
zip -r /tmp/EXP_45.zip EXP_45

相关内容

  • 没有找到相关文章

最新更新