# rsync
## Guide to using `rsync`
https://www.digitalocean.com/community/tutorials/how-to-use-rsync-to-sync-local-and-remote-directories
- `-a` to preserve permissions, modification timestamps etc
- `-z` to compress during file transmission
- `-n` to dry run
- `-h` (h)uman-readable
- `-P` (P)rogress
- `-s` to allow spaces in remote names over ssh ([Source](https://askubuntu.com/questions/597605/rsync-over-ssh-path-with-spaces-does-not-work-with-quotes): [[Stack Overflow]])
- `--delete` Delete files not present in source
- `--info=progress2` Show global progress
- Folder vs contents of folder
- `src/` `dest/`: copy contents of `src` into `dest`
- `src` `dest/`: copy `src` itself into `dest`
### Example
```bash
rsync -avuzhEP --rsh=ssh '/path/to/source' '/path/to/dest'
```
### Removing source files
Source: [[nixCraft]] - https://www.cyberciti.biz/faq/linux-unix-bsd-appleosx-rsync-delete-file-after-transfer/
You need to pass the `--remove-source-files` option to the rsync command. It tells rsync to remove from the sending side the files (meaning non-directories) that are a part of the transfer and have been successfully duplicated on the receiving side. Do not pass the `--delete` option to rsync command as it delete extraneous files from destination directory.
## Troubleshooting
### Files with _ in name
https://serverfault.com/questions/824167/rsync-over-sshfs-skips-filenames-starting-with-underscore
If there are "file not found" errors, remove the `noappledouble` flag from the mount command of the source / dest volumes
### Permission denied
Ensure the remote user has ownership over the target directory.
On remote machine
```bash
chown -R <remote_user> path/to/directory
```