- Option 1: Don't include hidden file
rsync -r --exclude=".*" source/ destination/
- Option 2: Include hidden file
rsync -avz source/ destination/
Note the slashes at the end of both paths. Any other syntax may lead to unexpected results!
The advantages of rsync are:
-
After the initial sync, it will then copy only the files that have changed.
-
You can use it over a network, convenient for files in $HOME, especially config files.
rsync -avz /var/www/public_html/source/.htaccess /var/www/public_html/dest/
rsync -avz /var/www/public_html/.htaccess root@<remote-ip>:/var/www/public_html/
- How to use rsync to backup a directory without git subdirectory
rsync -avz --exclude='.git/' source/ destination/
- Copying files using rsync from remote server to local machine:
rsync -chavzP --stats user@remote.host:/path/to/copy /path/to/local/storage
rsync -chavzP -e "ssh -p $portNumber" user@remote.host:/path/to/copy /local/path
Or from the remote host, assuming you really want to work this way and your local machine is listening on SSH:
rsync -chavzP --stats /path/to/copy user@host.remoted.from:/path/to/local/storage