Copy a directory into another directory while ignoring specific directories or files
Hey LQ,
I've been racking my brains for a few hours on this one and I'm pretty fed up. I turn to the pro's now. This is for my clients webserver. I want to be able to mirror their entire live public_html/ directory into a different directory that is also located inside the public_html/ directory. So something like: Code:
/public_html/ to /public_html/destination_directory/ I've been reading up on the "cp" command but it doesn't really seem like it can do this. I've tried doing things like Code:
cp !(/public_html/destination_directory) /public_html/ /public_html/destination_directory I want to specifically ignore multiple directories and files and I will be running this command through the PHP function system(), so I'm not sure what terminal equivalent that would be. The VPS Webhost is CentOS if that helps at all. Thanks so much in advance! |
You're almost there ...
first, make sure extglob is on for this activity: shopt -s extglob Then: cd public_html cp !(destination_directory) destination_directory |
Quote:
Btw, thank you for chiming in. |
Quote:
You'd have to find a way of doing this from the same session, so maybe slap shop -s extglob and your cp into a script, and run THAT from your system() call. Cheers, Tink |
Quote:
Something like: Code:
system('shop -s extglob; cp !ignoresomestuff source_dir destination_dir';) |
Quote:
Code:
$ cat test.php Code:
php -f test.php Cheers, Tink |
Quote:
Now, one last question. If I want to ignore multiple files do I use commas? Example: Code:
cp !(file1,file2,directory1,directory2) source destination Edit: I have just tried running this: Code:
shopt -s extglob; cp !test_file.txt /home/admin/public_html/dev/test/source_dir/* /home/admin/public_html/dev/test/destination_dir |
I think I know what you're doing wrong ;}
for the glob to work you need to be in the source dir. shopt -s extglob; cd /home/admin/public_html/dev/test/source_dir/; cp !(test_file.txt) /home/admin/public_html/dev/test/destination_dir |
So... if you do "cp" from inside of a dir with out specifying (*) it just assumes every file and directory in the cwd?
|
Everything that doesn't match what you have in !() ... that's the whole idea of that glob.
|
Code:
shopt -s extglob; cd /home/admin/public_html/dev/test/source_dir/; cp !(test_file.txt) /home/admin/public_html/dev/test/destination_dir Code:
find /home/admin/public_html/dev/test/source_dir/ ! -name "test_file.txt" | cpio -admp home/admin/public_html/dev/test/destination_dir Code:
/home/admin/public_html/test/source_dir/test_file_2.txt |
How about a local rsync using exclude option http://www.thegeekstuff.com/2011/01/...s-and-folders/
|
Quote:
I only have one issue... Every time I run my back up command it changes the file permission of my destination directory to 750 when it's supposed to be set at 755... Any idea why that might be? |
Is that using rsync? If so, checkout the various flags available.
I usually go with -a Quote:
Basically, those implied flags preserve just about everything ... :) |
Rsync is running from PHP on my VPS. I do a manual CHMOD from PHP to get around the issue and it works great. Thanks for your help!
|
All times are GMT -5. The time now is 12:28 AM. |