Server 1 is connected to Server 2 via SSH.
We know this:
I can execute a command such as
” ssh server2 “cp -rv /var/www /tmp” “
which will copy the entire /var/www dir to /tmp. However inside of /var/www we have the following structure(sample LS output below)
$ ls
/web1
/web2
/web3
file1.php
file2.php
file3.php
How can I execute a cp command that will exclude /web1, /web3, file1.php and file3.php (obviously just copying web2 and file2 is not an option since there are significantly more files than just 6)
Note: I am using this to backup Server2 prior to RSYNCing from Server1.
The first two poster’s both have good suggestions about rsync. Here’s a more complete outline of the process.
(1) You want to backup server 2 before you sync from server 1, so let’s do that with
rsync. Here’s the command as seen from server 1 (assuming it has access to server 2):(2) With server 2 backed up, let’s now sync from server 1 (again, as seen from server 1)
As long as you use sane
RSYNC_OPTS, the backup and sync should both be reasonable. Richard had a reasonable suggestion for the options:If you want an accurate reproduction, I’d recommend
--deleteor--delete-afteras well. Be sure to lookup details on any options you’re unfamiliar with.