问题描述:

I am creating an automatic backup system. I plan on running a Cron Job that will, once a week, automatically create a backup and email it to a secure email.(this way, even if the server explodes into a million pieces I will have a full recent backup of my files that any administrator can access)

I found this simple method: system('tar -cvzpf backup.tar.gz /path/to/folder');

It works nearly perfectly for what I need. Only problem is there is one directory that I do not want included in the backup. On this website, users upload their own avatars and the directory in which the images are held is inside the directory I want backed up. Because I'm sending this via email I have to keep the folder relatively small, and a couple thousand images add up. Is there any way I could tell the function to ignore this directory and just compress everything else?

网友答案:

From the tar man:

 tar --exclude='/path/to/folder/bad' 

So you would get:

system('tar -czpf --exclude='/path/to/folder/bad'  backup.tar.gz /path/to/folder');

You can leave the v (verbose) out, since you are not watching your code being executed.

网友答案:

find /path/to/folder -not -ipath '*baddirectory*' -print | xargs tar -cvzpf backup.tar.gz though you might consider passing PHP the full path to all the binaries you use (in the above command: find, xargs, and tar).

网友答案:

You can exclude something from been included with --exclude-tag-all PATTERN long option as on manual. Unfortunely I did not found a good example about pattern.

I guess the following exclude will work:

--exclude-tag-all=/path/foldernotinclude/.

Since it should match the "directory" file tag.

With lucky another user will make a comment about patern to use.

相关阅读:
Top