How to compact directory except a specific folder via SSH with zip command?

Asked

Viewed 453 times

0

I have to compress all the files and directories of the directory public_html except for var which has more than 60GB. How can I perform this operation via SSH commanding zip? I saw some shapes with different commands tar and others but need to perform this operation with command zip.

I just want to compact without the var and not erase it from the hosting.

2 answers

3


Searching the man zip found the option --exclude or -x, believe this is exactly what you need.

-x files
       --exclude files
              Explicitly exclude the specified files, as in:

                     zip -r foo foo -x \*.o

              which  will  include  the  contents  of foo in foo.zip while excluding all the files that end in .o.  The backslash avoids the shell filename substitution, so that the name
              matching is performed by zip at all directory levels.

              Also possible:

                     zip -r foo foo [email protected]

              which will include the contents of foo in foo.zip while excluding all the files that match the patterns in the file exclude.lst.

              The long option forms of the above are

                     zip -r foo foo --exclude \*.o

              and

                     zip -r foo foo --exclude @exclude.lst

              Multiple patterns can be specified, as in:

                     zip -r foo foo -x \*.o \*.c

              If there is no space between -x and the pattern, just one value is assumed (no list):

                     zip -r foo foo -x\*.o

              See -i for more on include and exclude.

1

You will have to run the command remotely, then:

ssh [email protected] -p 2255 'zip backup.zip /public_html --exclude var'

the command will ask the user password and ready, you will have your file compressed.

Ps.: Obviously you need to adapt the command to your scenario, in case -p 2255 is the connection port to the SSH

Browser other questions tagged

You are not signed in. Login or sign up in order to post.