LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Excluding a file when using pax (https://www.linuxquestions.org/questions/linux-general-1/excluding-a-file-when-using-pax-318001/)

tobycatlin 04-28-2005 05:33 AM

Excluding a file when using pax
 
I am using pax to backup my files and need to exclude a couple of large files. The file names never change.

From reading the man pages i should use the -c operator but it doesn't give any examples. this is my best guess but it says i am using a invaild combination of w c and f

pax -w -f test /root/code_samples -c /root/code_samples/phpMyAdmin-2.6.2.zip

Does anyone know how to exclude a file??

thanks

t

homey 04-28-2005 08:29 AM

I think pax could turn out to be a nice little gem and may have to check it out some more. :)
The man page can be a bit confusing for sure but here is an excellent article. The -c option is on page three and is used like this.... -c './Linux Stuff' where that is the directory which I don't want restored.
http://www.onlamp.com/pub/a/bsd/2002...cs.html?page=1

Here is an example I used.
Code:

# ls
Linux Stuff  Linux Technical Docs

# I cd into the Linux directory and make a backup file called backup
pax -wf /home/backup .

# Now I want to restore everything exept the directory called "Linux Stuff"
# In this example, I'll restore to /home/images for testing purposes.
cd /home/images
pax -rvf /home/backup -c './Linux Stuff'

Don't forget to use single quotes on the file or directory to exclude from the restore.

tobycatlin 04-28-2005 09:05 AM

so the -c flag is only good for excluding a folder from being restored?
Not excluding it from being in the backup in the first place?

homey 04-28-2005 09:09 AM

That's what I gather so far. I'll have to do some more checking to see what other options there are but I don't think -c is used during save operations.

tobycatlin 04-28-2005 09:20 AM

what i want to do it to backup a users site into a single file and then offer it back to them so that they can download it and save it. (Basically so they are ultimately responsible for the data and not me)

My users like many others are a bit thick and we have advertised as a 'no extra software required' websites. So i would like to avoid using a FTP client. It would be great if the user just clicks a link and off they go.

Therefore i thought if i can backup /home/website1 and then copy that file to /home/website1/backup the users can download from /home/website1/backup directly (obviously with sufficent authentication)

This leads to the problem that the next time the backup is run it will backup the backup. Because the user is downloading the backup file it is vital that it is as small as possible.

tobycatlin 04-28-2005 09:21 AM

Can specific file be removed from the backup file after creation??

homey 04-28-2005 09:30 AM

Quote:

(Basically so they are ultimately responsible for the data and not me)
You are about to find out just how "thick" these people can be. :)

I don't know what all options you can use.

tobycatlin 04-28-2005 09:49 AM

the man reason i am doing this is because one of my users deleted all the products out of the database then phoned me asking what the undo command was. He wasn't happy when i said there wasn't one. I did have a backup but it was before he added 400 products, again he wasn't happy.

I am open to any and all suggestions

thanks for your help

frob23 04-28-2005 11:02 AM

Code:

find /path/to/dir -name "*" | grep -v "file_to_exclude" | pax -w -d -x ustar | bzip2 > name_of_tar.tar.bz2
Okay this is involved but not too complicated. The find command is going to find every single file in their directory. It will pass that to the grep command, which will remove the lines which match the pattern of the file you don't want (use the whole name and path -- look at the find output to determine what this is -- to make sure you get only it). The grep command pipes all those filenames to pax... which writes an archive. The -d flag is what is important. It tells pax to match directories but not all the files beneath it. Basically, it says "only archive what I specifically name". In this case I use ustar as my format but you can use whichever makes sense for your users and is supported. I also pass it through bzip2 to compress it as well. This may or may not work for you (if you don't think your users will have bunzip2 or access to a program that will handle it).

frob23 04-28-2005 11:13 AM

Okay, here it is in more of a script format.
Code:

#!/bin/sh
DIRECTORY=/directory/to/backup
EXCLUDE="backup/backup.file.name.tar.bz2"
COMPRESS=bzip2
ARCHIVE=$DIRECTORY/$EXCLUDE
find $DIRECTORY -name "*" |\
grep -v $EXCLUDE |\
pax -w -d -x ustar |\
$COMPRESS > $ARCHIVE

Note, you could pass each user's directory as an argument and just assign it to DIRECTORY, or you could modify this script to step through each one... and do this for each. But it gives you the basic idea.


All times are GMT -5. The time now is 12:00 AM.