Search code examples
linuxubuntuplsqlzipdbms-scheduler

Zip compress without root folders


My problem is that I have to generate a zip file using the linux zip console command. My command is as follows:

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

That returns a correct zip only that includes the root folders I want:

Returns

EXP_45.zip

-folder1

--folder2

---EXP_45

...

I want

EXP_45.zip

-EXP_45

...

EXP_45 is a folder that can contain files and folders and they must be present in the zip. I just want the tree structure to start with the EXP_45 folder.

Is there any solution?

The reason why I need it to be a single command is that it is an action of a job in a PL SQL function like:

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;

Solution

  • I haven't been able to find a solution to this problem using zip but I have found it using jar. The command would be:

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

    Also, the solution using a job in pl sql in case it works for someone would be:

    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;